Hi everyone. I am new to this forum, so I might be asking questions that have already been asked, but here it goes anyway.
I am trying to run a macro with a command button that will open another excel file. But what I need it to do is when the second excel files opens, I need it to run a macro that is within that file. I have included the code I am using:
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click
' Button launches Word and opens a specified document
' And runs an optional macro. the macro could print out the word doc and quit
Dim retval As Variant
Dim docName, MacroName As String
' Drive and Full path to name and location of Word document
'docName = "C:\Documents_and_Settings\Owner\Desktop\testfile.xls"
'Optional Macro Name. Note Word Macro name cannot have any spaces in it.
MacroName = "/M" & "test"
'Note full path to Word including Drive and folder
retval = Shell("C:\Program Files\Microsoft Office\Office\EXCEL.EXE C:\testfile.xls" & "" & MacroName, vbNormalFocus)
Exit_Command1_Click:
Exit Sub
Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub
What I also need it to do is close the newly opened excel file once the macro has run.
I hope I make sence here![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Thanks for your help and advise
Shcuck
I am trying to run a macro with a command button that will open another excel file. But what I need it to do is when the second excel files opens, I need it to run a macro that is within that file. I have included the code I am using:
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click
' Button launches Word and opens a specified document
' And runs an optional macro. the macro could print out the word doc and quit
Dim retval As Variant
Dim docName, MacroName As String
' Drive and Full path to name and location of Word document
'docName = "C:\Documents_and_Settings\Owner\Desktop\testfile.xls"
'Optional Macro Name. Note Word Macro name cannot have any spaces in it.
MacroName = "/M" & "test"
'Note full path to Word including Drive and folder
retval = Shell("C:\Program Files\Microsoft Office\Office\EXCEL.EXE C:\testfile.xls" & "" & MacroName, vbNormalFocus)
Exit_Command1_Click:
Exit Sub
Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub
What I also need it to do is close the newly opened excel file once the macro has run.
I hope I make sence here
Thanks for your help and advise
Shcuck