Running code in Excel via Access using GetObject (1 Viewer)

Angielah

Registered User.
Local time
Today, 20:20
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
 

Mario

Registered User.
Local time
Today, 15:20
Joined
Jul 3, 2002
Messages
67
Can't you run your macro Auto_Open through your object? ie.: ExcelWorksheet1.Auto_Open.Run
 

Angielah

Registered User.
Local time
Today, 20:20
Joined
Jul 9, 2002
Messages
11
Will give that a go.
Thanks
Angie
 

Angielah

Registered User.
Local time
Today, 20:20
Joined
Jul 9, 2002
Messages
11
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
 

doulostheou

Registered User.
Local time
Today, 14:20
Joined
Feb 8, 2002
Messages
314
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]"
 

Angielah

Registered User.
Local time
Today, 20:20
Joined
Jul 9, 2002
Messages
11
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
 

Fornatian

Dim Person
Local time
Today, 20:20
Joined
Sep 1, 2000
Messages
1,396
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:

Angielah

Registered User.
Local time
Today, 20:20
Joined
Jul 9, 2002
Messages
11
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

Top Bottom