Running a macro in ThisWorkBook on an external workbook

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I found this code from user 30percent from 2011 and am trying to adapt it for my use.

I am trying to run:
Thisworkbook = New System 80E-1.xlsm
Macro to run in this workbook = CreateUniqueBDIF

On an external workbook called Results.xlsx.

VBA Code:
Sub Open_External_Workbook_Run_Macro()
Dim open_Workbook As Workbook
Dim wb As Workbook
Workbooks.Open Filename:="C:\Users\jeff\Desktop\BetfairBot\Results.xlsx"
Set open_Workbook = Application.Workbooks.Open("C:\Users\jeff\Desktop\BetfairBot\Results.xlsx")
Set wb = Workbooks.Open("C:\Users\jeff\Desktop\New Horses\New System 80E-1.xlsm")
Application.Run wb.Name & "!" & "CreateUniqueBDIF"
End Sub

However, I keep getting this 104 error:

1704000318184.png


saying the macro is not available, when it is definitely there.

Can somebody please tell me what I am doing wrong.
Thanks in advance for your help.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You workbook name New System contains spaces so you need to have single quotes around the workbook name:

Rich (BB code):
    Application.Run "'" & wb.Name & "'!" & "CreateUniqueBDIF"

PS: You are also opening the same Results workbook twice, you don't need this line.
Rich (BB code):
    Workbooks.Open Filename:=ThisWorkbook.Path & "\Results.xlsx"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top