Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Excel files from MS Access...

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
0
0
US
I have been using Excel for reporting from MS Access from some time...my "MO" has been as follows:

Code:
Sub mike()
Dim xlApp as New Excel.Application, xlWkb as Excel.Workbook
set xlWkb=xlApp.Workbooks.Open(myPath & myFile)
etc.
etc.
End Sub

I need to know now, though, how to use an instance of Excel that is already running. I tried

Code:
Sub mike()
Dim xlApp as Excel.Application, xlWkb as Excel.Workbook
set xlWkb=Excel.Application.Workbooks("AlreadyOpen.xls")
Msgbox xlWkb.Name
End Sub

but I keep getting the "subscript of of range" error message.

Any suggestions?

Thanking you in advance,

Mike K
 
OK, I had it, then I lost it. I did:
Code:
Sub mike()
dim xlApp as Excel.Application, xlWkb as Excel.Workbook
set xlApp=CreateObject("Excel.Application")
set xlWkb=xlApp.Workbooks("AlreadyOpen.xls")
msgbox wkWkb.Worksheets.Count
End Sub
It worked the first time I tried it, and then every time after that I got the "subscript out of range.." error message on the line that reads "set xlwkb=xlapp.Workbooks...".
Thanks for your help. Mike K
 
OK, got it.
Use GetObject instead of CreateObject.
It works.
Answering my own questions here...just so no one else will waste their time!! Mike K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top