PC Review


Reply
Thread Tools Rate Thread

Call Add-In Macro from VBA

 
 
=?Utf-8?B?V0NN?=
Guest
Posts: n/a
 
      20th Jan 2007
I created a simple add-in that contains one module (module1) and that module1
contains a simple macro (macro1). I posted that add-in to a file folder on my
desktop and then added it to my Excel Application. So, if I look in the VB
Editor I can see the new .xla as a separate project in every Excel Workbook I
open.

QUESTION:
I can attach that .xla macro1 to a toolbar command icon (and it works). I
can also attach it to a simple Excel 'Button' and that works, too.

But when I insert a VB command button into a worksheet, and then add a
simple procedure to the click event, I cannot get the .xla macro to run. What
is the proper syntax? The following (or any other longer syntax I use)
doesn't work:

Private Sub CommandButton1_Click()
Macro1
End Sub

Thanks,
wcm
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      21st Jan 2007
There are two ways to do this. The first is with the Run method. Use
something like

Application.Run "AddinName.xla!MacroName"

The second is to reference the addin. First of all, you should give your
add-in a meaningful project name. Open your add-in in the VBA Editor, go to
the Tools menu, and choose "VBA Project Properties". In that dialog, change
the name of the project from "VBAProject" to something meaningful. Save the
Add-In.

Then open the workbook from which you want to call the macro in the add-in.
Go to the Tools menu, choose References, and in the list find the Project
Name (not the workbook name) that you change in the previous step. Put a
check next to that project item. Then, once the reference is established
from the workbook to the add-in, you can call the macro in the add-in by
simply using its name.

Macro1


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)




"WCM" <(E-Mail Removed)> wrote in message
news:ED88E2D8-B3E5-481F-B885-(E-Mail Removed)...
>I created a simple add-in that contains one module (module1) and that
>module1
> contains a simple macro (macro1). I posted that add-in to a file folder on
> my
> desktop and then added it to my Excel Application. So, if I look in the VB
> Editor I can see the new .xla as a separate project in every Excel
> Workbook I
> open.
>
> QUESTION:
> I can attach that .xla macro1 to a toolbar command icon (and it works). I
> can also attach it to a simple Excel 'Button' and that works, too.
>
> But when I insert a VB command button into a worksheet, and then add a
> simple procedure to the click event, I cannot get the .xla macro to run.
> What
> is the proper syntax? The following (or any other longer syntax I use)
> doesn't work:
>
> Private Sub CommandButton1_Click()
> Macro1
> End Sub
>
> Thanks,
> wcm



 
Reply With Quote
 
=?Utf-8?B?V0NN?=
Guest
Posts: n/a
 
      21st Jan 2007
Just got my answer from a post just before mine (but didn't see until now),
so here it is, thanks to merjet:

Application.Run "FileName.xla!macro1"


"WCM" wrote:

> I created a simple add-in that contains one module (module1) and that module1
> contains a simple macro (macro1). I posted that add-in to a file folder on my
> desktop and then added it to my Excel Application. So, if I look in the VB
> Editor I can see the new .xla as a separate project in every Excel Workbook I
> open.
>
> QUESTION:
> I can attach that .xla macro1 to a toolbar command icon (and it works). I
> can also attach it to a simple Excel 'Button' and that works, too.
>
> But when I insert a VB command button into a worksheet, and then add a
> simple procedure to the click event, I cannot get the .xla macro to run. What
> is the proper syntax? The following (or any other longer syntax I use)
> doesn't work:
>
> Private Sub CommandButton1_Click()
> Macro1
> End Sub
>
> Thanks,
> wcm

 
Reply With Quote
 
=?Utf-8?B?V0NN?=
Guest
Posts: n/a
 
      21st Jan 2007
Chip:
Thank you. Didn't see your post until today, so would have answered sooner.
This is exactly what I needed, and thanks for two working alternatives.


"Chip Pearson" wrote:

> There are two ways to do this. The first is with the Run method. Use
> something like
>
> Application.Run "AddinName.xla!MacroName"
>
> The second is to reference the addin. First of all, you should give your
> add-in a meaningful project name. Open your add-in in the VBA Editor, go to
> the Tools menu, and choose "VBA Project Properties". In that dialog, change
> the name of the project from "VBAProject" to something meaningful. Save the
> Add-In.
>
> Then open the workbook from which you want to call the macro in the add-in.
> Go to the Tools menu, choose References, and in the list find the Project
> Name (not the workbook name) that you change in the previous step. Put a
> check next to that project item. Then, once the reference is established
> from the workbook to the add-in, you can call the macro in the add-in by
> simply using its name.
>
> Macro1
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email address is on the web site)
>
>
>
>
> "WCM" <(E-Mail Removed)> wrote in message
> news:ED88E2D8-B3E5-481F-B885-(E-Mail Removed)...
> >I created a simple add-in that contains one module (module1) and that
> >module1
> > contains a simple macro (macro1). I posted that add-in to a file folder on
> > my
> > desktop and then added it to my Excel Application. So, if I look in the VB
> > Editor I can see the new .xla as a separate project in every Excel
> > Workbook I
> > open.
> >
> > QUESTION:
> > I can attach that .xla macro1 to a toolbar command icon (and it works). I
> > can also attach it to a simple Excel 'Button' and that works, too.
> >
> > But when I insert a VB command button into a worksheet, and then add a
> > simple procedure to the click event, I cannot get the .xla macro to run.
> > What
> > is the proper syntax? The following (or any other longer syntax I use)
> > doesn't work:
> >
> > Private Sub CommandButton1_Click()
> > Macro1
> > End Sub
> >
> > Thanks,
> > wcm

>
>
>

 
Reply With Quote
 
 
 
Reply

« Add-in | Argument »
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
call to macro in xlam from macro in xlsb SteveDB1 Microsoft Excel Programming 1 2nd Jul 2008 11:55 PM
Call an Access macro from an Excel macro Jason W Microsoft Excel Misc 1 1st May 2008 08:33 PM
Re: Excel Macro call Word Macro with Parameters =?Utf-8?B?Q3VydA==?= Microsoft Excel Programming 0 24th May 2007 12:21 AM
Call macro stored in Excel workbook from Outlook's macro =?Utf-8?B?R3ZhcmFt?= Microsoft Excel Programming 0 4th Oct 2006 05:47 PM
Call macro stored in Excel workbook from Outlook's macro =?Utf-8?B?R3ZhcmFt?= Microsoft Outlook VBA Programming 5 4th Oct 2006 06:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:56 PM.