Calling Procedures From Other Workbooks

sachin.acharya

Board Regular
Joined
Nov 5, 2009
Messages
93
Hi all,

From within the code in an Add-In I am trying to call a procedure from the ActiveWorkbook. So my code looks somewhat like:

HTML:
Sub MyProcedureInAddin()
  'My code here...
  Run ActiveWorkbook.Name & "!SomeProcedure"
  'My code continues...
End Sub

This works fine if ActiveWorkbook.Name does not have spaces. But say if my ActiveWork.Name is "Blah Blah Blah.xls" it gives the error:

Cannot run the macro 'Blah Blah Blah.xls!SomeProcedure'. The macro may not be available in this workbook or all macros may be disabled.

Is there a way around this so that I don't have to rename or save the active file without spaces?

Thanks.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You know how excel tacks the brackets around the address to links? Try building a string variable that equates this. As I recall, the brackets being there when un-needed do no harm, but are required when the filename has spaces.

Mark
 
Upvote 0
Try...

Code:
Run "'" & ActiveWorkbook.Name & "'!SomeProcedure"
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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