Auto run macro
The workbook must be open and you don't use the path in the application.run
line.
If workbook2.xls isn't open, you can open it in code:
Dim wkbk as workbook
set wkbk = nothing
on error resume next
set wkbk = workbooks.open _
(filename:=thisworkbook.path & application.pathseparator & "workbook2.xls")
on error goto 0
if wkbk is nothing then
msgbox "That file didn't open!"
March wrote:
Here is my code
Sub Workbook_Open()
txttemp = ThisWorkbook.Path & Application.PathSeparator & "WorkBook2.xls"
Application.Run txttemp!Workbook_Analysis
End Sub
Workbook_Analysis is the macro name
I want the file is auto open too. The first line works. The second line
doesn't work now.
In my opionion the second line might need to put something for the
concatenetion.
Anyways, please give me suggestion.
Thanks,
March
"Dave Peterson" wrote:
Inside the second workbook's project:
Dim OtherWkbk as workbook
set otherwkbk = workbooks("otherworkbookname.xls") '<-- it has to be open
application.run "'" & otherwkbk.name & "'!somemacronamehere"
or
application.run "'" & otherwkbk.name & "'!somemacronamehere", myargument
or to return something:
dim resp as long 'or string or whatever
resp = application.run("'" & otherwkbk.name & "'!somemacronamehere", _
myargument)
March wrote:
Dear All,
I want to run automated macro in two workbooks. I means I have two workbooks
one centain macro and another one does not for now.
For the second one, I want to write VBA to call the Macro function from the
first one. I don't know what should I start now.
Please give me suggestion.
Thanks,
March
--
Dave Peterson
--
Dave Peterson
|