I have opened an excel file in my VB project and I want to excecute an existing macro in my workbook.
Dim Classeur As Workbook
Set Classeur = Workbooks.Open("d:\file.xls")
Workbooks.Close
have you an idea?
Thanks
Printable View
I have opened an excel file in my VB project and I want to excecute an existing macro in my workbook.
Dim Classeur As Workbook
Set Classeur = Workbooks.Open("d:\file.xls")
Workbooks.Close
have you an idea?
Thanks
Here :
Open the workbook then press Alt-F8 or click Tools -> Macro -> Macros and highlight macro name and click Run button.
[Edited by shinned on 05-30-2000 at 09:47 AM]
I think he is trying to run the macro automatically out of the VB project.
In Excel, start the macro recorder, open the sheet with the macro, run the macro. Stop the macro recorder, and go look at the code generated for opening the sheet and running the macro.
This is what I got:
Code:
Workbooks.Open FileName:="C:\My Documents\Test Macro.xls"
Application.Run "'Test Macro.xls'!MoveEmail"
For Excel use the following:
Code:Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
DoEvents 'Pause until everything previously has been process
' PURPOSE:Technique to run a macro in another Microsoft Application
' Another technique would be sticking the pBrain macro into the "Open" event
xlApp.Workbooks.Open FileName:=gstrTemplateDirectory & "FormatText.xls"
xlApp.Run "FormatText.xls" & "!pBrain"
For Word use the following:
Code:Set xlApp = CreateObject("Word.Application")
xlApp.Visible = True
DoEvents 'Pause until everything previously has been process
' PURPOSE:Technique to run a macro in another Microsoft Application
' Another technique would be sticking the pBrain
' macro in "Macro.doc" into the "Open" event
xlApp.Documents.Open FileName:=gstrTemplateDirectory & "Macro.doc", PasswordDocument:="Testing"
' PURPOSE: Call this macro
xlApp.Run MacroName:="pBrain"