Error calling macro in add-in and passing variable

EdNerd

Active Member
Joined
May 19, 2011
Messages
464
(XL2007, Vista) I am creating a new worklbook from a template. One of the sheets in the new workbook has a selection of three cells as "buttons". The Worksheet_SelectionChange event is supposed to call a macro in an add-in and pass the Target.Address as a string variable.

I did just have the three cells call three separate macros from the add-in, without passing any variables, and those worked fine. But then it dawned on me that I couldn't add any new functionality in files created on that template because I couldn't get to the VBE to add a call to a new macro. So if I just call a macro in the add-in that figured out what to do based on the Target.Address, then I could update the add-in as needed with new functions.

Now, though, calling the add-in macro gets me a 1004 error:
"Cannont run the macro 'MyAddIn.xlam!doTarget(strAddress)'. The macro may not be available in this workbook, or all macros may be disabled."

Any help on fixing this?
Ed

In worksheet:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim strAddress As String
strAddress = Target.Address
Application.Run "MyAddIn.xlam!doTarget(strAddress)"
End Sub

In add-in:
Code:
Sub doTarget(strAddress As String)
Select Case strAddress
  Case "$H$23:$J$24"
    Call doRows
  Case "$H$27:$J$28"
    Call doNames
  Case "$H$31:$J$32"
    Call doFreeze
End Select
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Code:
Application.Run "MyAddIn.xlam!doTarget" , strAddress
should do it.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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