ststern45
Well-known Member
- Joined
- Sep 17, 2005
- Messages
- 974
- Office Version
- 365
- 2010
- Platform
- Windows
Hi everyone,
I have a question on how to run 2 macros in a second workbook
I have Workbook 1 open and I want to update a total of 42 worksbooks (workbook 2, 3, etc. using the calculations from Workbook 1
Can I use the workbook2 name in cell A2?. Example: workbook2.xlsm
This is the code below and I know it's likely incorrect:
Sub RunMacrosIn2Workbooks()
Sname1 As String
'Cell A1 contains the name of the Workbook 2 to open
Sname1 = Sheets("Sheet1").Range("A1").Value
'Open workbook 2
Workbooks.Open (Sname1)
Sheets("Dashboard").Select
'run 1st macro in workbook 2
Application.Run (" 'Workbook2.xlsm' !ClearPreviousResults1")
'run 2nd macro in workbook 2
Application.Run (" 'Workbook2.xlsm' !CopyData1")
'Save and Close Workbook 2
ActiveWorkbook.Close True
Windows("Workbook1.xlsm").Activate
Sheets("sheet1").Select
Range("B1").Select
End Sub
My question is, can I use the following 2 lines of code instead of the 2 lines of code above?
'run 1st macro in workbook 2
Application.Run (" 'Sname1' !ClearPreviousResults1")
'run 2nd macro in workbook 2
Application.Run (" 'Sname1' !CopyData1")
Thank you
I have a question on how to run 2 macros in a second workbook
I have Workbook 1 open and I want to update a total of 42 worksbooks (workbook 2, 3, etc. using the calculations from Workbook 1
Can I use the workbook2 name in cell A2?. Example: workbook2.xlsm
This is the code below and I know it's likely incorrect:
Sub RunMacrosIn2Workbooks()
Sname1 As String
'Cell A1 contains the name of the Workbook 2 to open
Sname1 = Sheets("Sheet1").Range("A1").Value
'Open workbook 2
Workbooks.Open (Sname1)
Sheets("Dashboard").Select
'run 1st macro in workbook 2
Application.Run (" 'Workbook2.xlsm' !ClearPreviousResults1")
'run 2nd macro in workbook 2
Application.Run (" 'Workbook2.xlsm' !CopyData1")
'Save and Close Workbook 2
ActiveWorkbook.Close True
Windows("Workbook1.xlsm").Activate
Sheets("sheet1").Select
Range("B1").Select
End Sub
My question is, can I use the following 2 lines of code instead of the 2 lines of code above?
'run 1st macro in workbook 2
Application.Run (" 'Sname1' !ClearPreviousResults1")
'run 2nd macro in workbook 2
Application.Run (" 'Sname1' !CopyData1")
Thank you