Reputation: 47
I created some code to open a workbook and run a macro saved in that workbook but I'm getting an error 'expected sub/function'. The code is below. Your help is greatly appreciated!
Sub practice()
Const folderPath As String = "I:\Ben\New Stores\Reports"
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim MyFolder As Object
Set MyFolder = fso.GetFolder(folderPath)
Application.Run "'6wk File to Run.xlsm'!button2_click"
End Sub
EDIT The working code is above
Upvotes: 0
Views: 139
Reputation: 84455
Something like (change worksheet name as appropriate and make sure macro is scoped to all openworkbooks). You may or may not need the sheet between the workbook name and the button2.
Application.Run ActiveWorkbook.Name & "!Sheet1.Button2_click"
Where Button2 is Public Scope
To make Button2 public simply make sure it is
Public Sub Button2_Click
Upvotes: 1