Running code in Excel via Access using GetObject

Angielah

Registered User.
Local time
Today, 01:00
Joined
Jul 9, 2002
Messages
11
Have managed to open an Excel file via Access by using GetObject. Code as follows.....

Set ExcelWorksheet1 = Nothing
Set ExcelWorksheet1 = GetObject("c:\bpm-teamlead\performance\Performancemacdata\pmac220502.xls")
ExcelWorksheet1.Activate
ExcelWorksheet1.Application.Visible = True


I want the code in pmac220502.xls to run as soon as it is opened. I have started with Auto_open.
However, GetObject doesn't seem to open it as it is minimised and greyed out which is why I put in the line "ExcelWorksheet1.Activate". This has given it the focus but of course Auto_open doesn't run as it as already opened by the GetObject command.
Really confused and would appreciate advice
Angie
 
Can't you run your macro Auto_Open through your object? ie.: ExcelWorksheet1.Auto_Open.Run
 
Will give that a go.
Thanks
Angie
 
Hi Mario
Tried your suggestion but got the following error message
"Object doesn't support this property or method"
Have you any other ideas
Angie
 
The following seems to work:

Code:
Dim ExcelWorksheet1 As Excel.Application
Set ExcelWorksheet1 = CreateObject("Excel.Application")
ExcelWorksheet1.Workbooks.Open "[color=blue]YourPath.xls[/color]"
ExcelWorksheet1.Visible = True
ExcelWorksheet1.Run "[Color=blue]YourMacroName[/Color]"
 
It works......!!!!!
Am delighted! Had to use As Object because it didn't like As Excel.Application for some reason.

Thank you so much Doulostheou

Angie
 
Another way of doing this is to use this method:

Application.FollowHyperlink "Path.xls"


Sub Auto_Open()
MsgBox "AutoOpen kicked in"
End Sub

or use the Workbook_Open event...

Private Sub Workbook_Open()
Auto_Open
End Sub
 
Last edited:
Well
My delight was short lived.......

After opening Excel up , Access still has more code to run. However once Access has finished running, my macro in Excel (which has lots more to do before it too can quit) decides to hang.

Oh Lawd
 

Users who are viewing this thread

Back
Top Bottom