GetObject Function

CAP101

Registered User.
Local time
Today, 22:54
Joined
Mar 18, 2001
Messages
20
I am attempting to open an excel workbook from access but excel is continually crashing. I have no problems opening workbooks outside of access so i'm assuming its the code thats messing it up.

Static wbWorkbook As Excel.Workbook


Set wbWorkbook = GetObject("C:\My Documents\MyFile.xls")

wbWorkbook.Application.Visible = True
wbWorkbook.Parent.Windows(1).Visible = True

Can anyone please suggest the proper way to use the GetObject function to simply open a workbook?
 
Code looks OK to me.

Are you ensuring that you release the memory after you have finished using the workbook.

Try adding a line like

set wbworkbook = nothing at a suitable point after you return to access. You use a msgbox to 'pause' access code while using excel then put the set ... = nothing after the msgbox line
 
Thanks for your reply GaryC. What corrected the problem is adding the line: wbWorkbook.activate

After that worked, i created a macro in excel and saved Personal.xls and then rehid it. Now i've had to change my code in access to: wbWorkbook.Parent.Windows(2).Visible = True The original .Windows(1) keeps opening the hidden Personal.xls. Any suggestions on how to stop this from happening?
 
Maybe this would be easier.

Call Shell("Excel.exe C:\mydocu~1\myfile.xls", 1)

It is very simple but it works
 

Users who are viewing this thread

Back
Top Bottom