View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How do I invoke a VB subroutine that exists in an Add-In?

To assign it manually, just type in the name
MyAddin.xla!MyMacro

in code

CommandBars("Worksheet Menu Bar").Controls("Tools") _
.Controls("Mybutton").OnAction = "MyAddin.xla!MyMacro"

--
Regards,
Tom Ogilvy

"Tom Doster" wrote in message
...
It's not working. I deleted the old Add-In. I removed it from the list in
the Add-In manager dialog box. I deleted my toolbar. I closed and

restarted
Excel. Then:

(1) I open the source .xls file.
(2) I save it as an Add-In.
(3) I close the source (saving it because it tells me it changed) - Now I
only have my PERSONAL.XLS open but it is hidden
(4) I open the Add-In file.
(5) I create a new toolbar
(6) From the Customize pop-up I add a Custom-Button (Categories: Macro,
Commands: Custom Button)
(7) I try to assign a macro to the button but there is no pop-up... How do

I
assign this button to the subroutine in Visual Basic?
(8) I go back several times to compile the code at the .xls level and then
starting from scratch at the .xla level - Doesn't work.
(9) I try the new add-in after adding it to the list: Nothing...

Any idea what I'm missing?

Thanks,
Tom
"Tom Ogilvy" wrote in message
...
Don't assign the macro to the button until you have made the file an

addin.

--
Regards,
Tom Ogilvy

"Tom Doster" wrote in message
...
I've created an Excel Visual Basic subroutine that I want to share as

an
Add-In. How do I make it so that the user can run the VB subroutine?

In the spreadsheet (.xls) source for the Add-In (.xla) I have created

a
new
toolbar with a button assigned to the main macro. Then I compile the

Visual
Basic code and save the workbook as an Add-In file. I then close all

files,
make the Add-In available through the Add-In manager, open a new
spreadsheet, select some cells and then click on the toolbar button

that
I
linked to the Visual Basic subroutine. Trouble is: The toolbar button

wants
to run VB script from the original spreadsheet, not from the Add-In.

How do I tell the Excel toolbar (or menu, or whatever) to run the

Visual
Basic subroutine that exists in my Add-In file?

Can I do that directly, or do I have to have some level of

indirection:
The
toolbar calls a regular Visual Basic program that invokes the

subroutine
in
the Add-In?

I have Microsoft Excel 2002 on Windows XP Pro.

Thanks,
Tom Doster