The Dude MAN
The Dude MAN

Reputation: 47

Calling a macro saved in a different workbook without linking

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

Answers (2)

QHarr
QHarr

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

Scoping in all open workbooks

To make Button2 public simply make sure it is

Public Sub Button2_Click

Upvotes: 1

DisplayName
DisplayName

Reputation: 13386

use

Application.Run (ActiveWorkbook.name & "!button2_click")

Upvotes: 2

Related Questions