Art Collins Posted October 20, 2004 Posted October 20, 2004 (edited) Visual Basic Code in Access I need some help in Microsoft Access. I have a command button on my form that I want to open an existing Microsoft Excel file. I've been trying to write visual basic code to activate this file. Is their away to do this? Thank You, Edited October 20, 2004 by Art Collins Quote
*Experts* DiverDan Posted October 20, 2004 *Experts* Posted October 20, 2004 Have you tried using a command line arguement? System.Diagnostics.Process.Start("excel.exe", "myFile.xls") Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Art Collins Posted October 22, 2004 Author Posted October 22, 2004 Have you tried using a command line arguement? System.Diagnostics.Process.Start("excel.exe"' date=' "myFile.xls")[/quote'] Can you give me an example on how that would be written in Visual Basic. Thank you, Quote
Wile Posted October 22, 2004 Posted October 22, 2004 I havent used Access in a while but, doesnt the normal wizard that appears when you add a button on a form in Access, give you an option to start Excel. Try running that wizard and look at what it generates, that should do the trick I think. OK, here is the code that is generated by the wizard: On Error GoTo Err_Command0_Click Dim oApp As Object Set oApp = CreateObject("Excel.Application") oApp.Visible = True 'Only XL 97 supports UserControl Property On Error Resume Next oApp.UserControl = True Exit_Command0_Click: Exit Sub Err_Command0_Click: MsgBox Err.Description Resume Exit_Command0_Click That seems to start Excel through automation, but doesnt load a file yet. But loading a file should be something that is available on the oApp object I think. Quote Nothing is as illusive as 'the last bug'.
Art Collins Posted November 3, 2004 Author Posted November 3, 2004 I havent used Access in a while but, doesnt the normal wizard that appears when you add a button on a form in Access, give you an option to start Excel. Try running that wizard and look at what it generates, that should do the trick I think. OK, here is the code that is generated by the wizard: On Error GoTo Err_Command0_Click Dim oApp As Object Set oApp = CreateObject("Excel.Application") oApp.Visible = True 'Only XL 97 supports UserControl Property On Error Resume Next oApp.UserControl = True Exit_Command0_Click: Exit Sub Err_Command0_Click: MsgBox Err.Description Resume Exit_Command0_Click That seems to start Excel through automation, but doesnt load a file yet. But loading a file should be something that is available on the oApp object I think. Thanks for the code. I still can't open a excel file, any suggestions. Quote
Administrators PlausiblyDamp Posted November 3, 2004 Administrators Posted November 3, 2004 Does it give any errors or just not work? What code have you got so far? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Art Collins Posted November 3, 2004 Author Posted November 3, 2004 Does it give any errors or just not work? What code have you got so far? On Error GoTo Err_Command0_Click Dim oApp As Object Set oApp = CreateObject("Excel.Application") oApp.Visible = True 'Only XL 97 supports UserControl Property On Error Resume Next oApp.UserControl = True Exit_Command0_Click: Exit Sub Err_Command0_Click: MsgBox Err.Description Resume Exit_Command0_Click This opens excel only. I've tried oApp = getobject and the path where the file is located. The top line of the excel file flashes on the screen. Then the error comes up saying Object dosen't support this property method. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.