Create button with addin/reference macro in another file

G

Guest

OK, I have a program that references an addin and runs the code in that. At a point, the adding creates a button and then adds the onaction property to it. The problem I am having is that I need that line of code to somehow reference a module of code in the active workbook. The workbook name will never be the same and I can get the name of the workbook no problem and put that into a variable, but when I put the variable on that line of code, it compiles fine but when it runs, it errors out

What I have done

Dim WBK As Workboo
Dim MacroName As Strin
Set WBK = ActiveWorkboo
MacroName = """" & WBK.Name & "!run_final" & """

Then I create the button and attach the macro

Selection.OnAction = MacroNam

But it will always error out when the code is executed

Stumped......Any help would be greatly appreciated!!
 
T

Tom Ogilvy

get rid of """""

MacroName = """" & WBK.Name & "!run_final" & """"

should be

MacroName = WBK.Name & "!run_final"

MacroName holds the string: Book1.xls!run_final

the way you are doing it is is holding the string "Book1.xls!run_final"

so the quotes become part of the name (which doesn't exist).

--
Regards,
Tom Ogilvy




netzig said:
OK, I have a program that references an addin and runs the code in that.
At a point, the adding creates a button and then adds the onaction property
to it. The problem I am having is that I need that line of code to somehow
reference a module of code in the active workbook. The workbook name will
never be the same and I can get the name of the workbook no problem and put
that into a variable, but when I put the variable on that line of code, it
compiles fine but when it runs, it errors out.
 
G

Guest

I tried that and it also failed, can you think of anything else that I might be missing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top