Need help with vb code

  • Thread starter Thread starter wayne
  • Start date Start date
W

wayne

I have an application where I retrieve access 97 data with a query, export
it to an excel spreadsheet (test.xls) and use a button on my form to open
excel. I need some help with the code to have excel open directly to the
file test.xls.

Right now my code is:

Dim oApp As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True

Thanks for any help in advance.
Wayne
 
Dim oApp As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
oApp.Workbooks.Open "C:\MyFolderName\text.xls"

Don't forget to close the EXCEL application when you're done (oApp.Quit) and
then set the oApp variable to Nothing.
 
wayne said:
I have an application where I retrieve access 97 data with a query, export
it to an excel spreadsheet (test.xls) and use a button on my form to open
excel. I need some help with the code to have excel open directly to the
file test.xls.

Right now my code is:

Dim oApp As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True

Thanks for any help in advance.
Wayne

Although I think you could do that via a "RunApp" action in a Macro, the
following worked for me (with a different file name):

Public Function OpenExcel()
Dim wks As Worksheet
Workbooks.Open "c:\MyFolder\test.xls"
Set wks = ActiveWorkbook.Worksheets(1)
wks.Activate
wks.Application.Visible = True
End Function 'OpenExcel()

I called this from a Macro containing the following action:

RunCode OpenExcel()

and you could link this Macro to the button on your Form (or on the
Switchboard).

-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
Back
Top