Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2008

Tip: Looking for answers? Try searching our database.

Making A Macro Generally Available

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sheldon - 11 Feb 2008 21:01 GMT
I've written a macro (I'll call it Macro1) that multiple people will
need to use.  From Macro1, (that exists in my PERSONAL.XLS), I created
an add-in on a common drive location and copied the code to
Macro1.xla, thus creating Macro1.xla as an add-in.  As a test, I
created a custom button in my Excel and associated it with the drive
location and name of Macro1.xla but it gets an error when I try to run
it.  I guess I'm confused with the overall process of what I need to
do to enable different users to run my macro without needing to have
their own copy.  And beyond that question, how would they actually run
the macro which runs from within an Excel spreadsheet that they open.
Thanks for any/all suggestions.
Sheldon Potolsky
Bernie Deitrick - 11 Feb 2008 21:34 GMT
Sheldon,

The best option is to create the commandbar on the fly, when the workbook is
opened, and delete the commandbar when the workbook is closed. Follow these
instructions and example code.

In the workbook's Thisworkbook object code module, place the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
DeleteCommandbar
End Sub

Private Sub Workbook_Open()
CreateCommandbar
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
  On Error GoTo NotThere
  Application.CommandBars("My Bar").Visible = True
  Exit Sub
NotThere:
  CreateCommandbar
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
  On Error Resume Next
  Application.CommandBars("My Bar").Visible = False
End Sub

In a regular code module, place the following:

Dim myBar As CommandBar
Dim myButton As CommandBarButton

Sub CreateCommandbar()

On Error Resume Next
DeleteCommandBar

Set myBar = Application.CommandBars.Add("My Bar")
With myBar
  .Position = msoBarTop
  .Visible = True
  .Enabled = True
  Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
  With myButton
      .Caption = "Hello"
      .Style = msoButtonIcon
      .FaceId = 137
      .Enabled = True
      .OnAction = "SayHello"
  End With
End With

End Sub

Sub DeleteCommandBar()
'Delete the commandbar if it already exists
  On Error Resume Next
  Application.CommandBars("My Bar").Delete
End Sub

Sub SayHello()
MsgBox "Hello there"
End Sub

You can add as many buttons or other menu items as you like.

HTH,
Bernie
MS Excel MVP

> I've written a macro (I'll call it Macro1) that multiple people will
> need to use.  From Macro1, (that exists in my PERSONAL.XLS), I created
[quoted text clipped - 8 lines]
> Thanks for any/all suggestions.
> Sheldon Potolsky
Sheldon - 13 Feb 2008 16:47 GMT
Thanks for the suggestion Bernie.  One thing I neglected to mention is
that the macro I wrote would be run from any number of spreadsheets so
I'm guessing that could make a difference in using the code you so
graciously provided.  I could provide a manual process of opening a
spreadsheet, pressing alt-F11, choosing the project (the .xla file)
and running the macro.  Not as nifty as I'd like but the macro is a
good 100x faster than the previous (manual) process that was run so
the 3-4 users would still be very happy anyway.
Sheldon Potolsky
Bernie Deitrick - 13 Feb 2008 18:01 GMT
Sheldon,

Save the file as an add-in, and have every user add the file trhough Tools / Add-ins...  browse for
the file.
Then it will be opened automatically when Excel is started.

HTH,
Bernie
MS Excel MVP

> Thanks for the suggestion Bernie.  One thing I neglected to mention is
> that the macro I wrote would be run from any number of spreadsheets so
[quoted text clipped - 5 lines]
> the 3-4 users would still be very happy anyway.
> Sheldon Potolsky
Sheldon - 18 Mar 2008 16:42 GMT
Bernie,

Sorry for taking awhile to get back to you but I was working on more
of the coding for this project and I've now completed that.  I did
what you said below...
** Save the file as an add-in, and have every user add the file
through Tools / Add-ins...  browse for
 the file.  Then it will be opened automatically when Excel is
started.**
...and that worked fine.  But if I want to manually add a button to
the Excel for the two current users, I don't have the visibility to
the add-in when I want to associate it with the button I created.  Any
suggestions would be appreciated.
Sheldon

> Sheldon,
>
[quoted text clipped - 17 lines]
>
> - Show quoted text -
Gord Dibben - 18 Mar 2008 18:14 GMT
Sheldon

Add-in macros are not visible in Tools>Macro>Macros but you can assign a macro
to your button by just typing the name of the macro in the dialog box.

Right-click on button and "Assign Macro".

Type the name like  MyMacro and OK

Gord Dibben  MS Excel MVP

>Bernie,
>
[quoted text clipped - 32 lines]
>>
>> - Show quoted text -
Sheldon - 20 Mar 2008 13:53 GMT
When I type in the name of my macro as you suggested, automatically
filled in for me by Excel (which I don't want) is the Excel filename.
Is this the expected "behavior" that one can expect from Excel in this
scenario?  Anyway, since the macro I wrote can be run from any number
of Excel files, this doesn't work for me.  However, looking elsewhere
in this forum I found where someone suggested prefacing the macro name
with the module name e.g. Module1.MyMacro and that seems to work fine
for me.  I will now try it on someone else's workstation.
Thank you,
Sheldon

> Sheldon
>
[quoted text clipped - 6 lines]
>
> Gord Dibben  MS Excel MVP
Gord Dibben - 20 Mar 2008 16:36 GMT
Excel should not append the macroname with the filename if the add-in is truly
an add-in.

Did you have "All open workbooks" selected at "macros in" dialog?

Was the add-in loaded at the time?

Gord

>When I type in the name of my macro as you suggested, automatically
>filled in for me by Excel (which I don't want) is the Excel filename.
[quoted text clipped - 17 lines]
>>
>> Gord Dibben  MS Excel MVP
Sheldon - 20 Mar 2008 19:27 GMT
Gord,
I did have "All open workbooks" selected at "macros in" dialog.
I *think* the add-in was loaded at the time but maybe that's the
issue.  How can I confirm this AND have the add-in loaded if it's
not?  I am basing my *think* answer on the Tools/Add-Ins dialog and
seeing my add-in listed with a checkbox next to it under Add-Ins
available.  However, if I go into VBE (alt-F11) and then Add-Ins/Add-
In Manager, I don't see my macro listed as an Available Add-In and, if
that is the issue, I'm not sure how to get it added there.
Thanks,
Sheldon

> Excel should not append the macroname with the filename if the add-in is truly
> an add-in.
[quoted text clipped - 28 lines]
>
> - Show quoted text -
Gord Dibben - 20 Mar 2008 22:08 GMT
When you go to the VBE hit CTRL + r to open the Project Explorer.

Your add-in will be one of the open projects if it is loaded.

If you assigned xyz to a button and then ran the macro but go no error message
about "macro xyz could not be found" I would assume the add-in was loaded.

You will not see it in the Add-ins Manager.

The Manager only lists and looks after add-ins that supply tools and functions
to the Visual Basic development environment.

Excel workbook add-ins do not fall into this category.

Gord

>Gord,
>I did have "All open workbooks" selected at "macros in" dialog.
[quoted text clipped - 40 lines]
>>
>> - Show quoted text -
Sheldon - 25 Mar 2008 21:03 GMT
Thank you Gord.  Well, my add-in was loaded but the button still
required the module name (Module1.MyMacro) for whatever reason.  I can
live with that as it works fine.  Thank you again.
Sheldon Potolsky

> When you go to the VBE hit CTRL + r to open the Project Explorer.
>
[quoted text clipped - 58 lines]
>
> - Hide quoted text -
Gord Dibben - 25 Mar 2008 21:24 GMT
Strange.

I cannot replicate the need to preface with Module1

A simple  MyMacro will do.

If not too sensitive could you email me your workbook/add-in?

Change the AT and DOT for my email address.

Gord

>Thank you Gord.  Well, my add-in was loaded but the button still
>required the module name (Module1.MyMacro) for whatever reason.  I can
>live with that as it works fine.  Thank you again.
>Sheldon Potolsky
Dave Peterson - 25 Mar 2008 22:30 GMT
Do you have another macro (sub or function) named myMacro in a different module?

How about an excel Name that uses myMacro?

> Thank you Gord.  Well, my add-in was loaded but the button still
> required the module name (Module1.MyMacro) for whatever reason.  I can
[quoted text clipped - 63 lines]
> >
> > - Hide quoted text -

Signature

Dave Peterson

Dave Peterson - 25 Mar 2008 22:30 GMT
Or even a module named myMacro?
Is the project named myMacro?

> Thank you Gord.  Well, my add-in was loaded but the button still
> required the module name (Module1.MyMacro) for whatever reason.  I can
[quoted text clipped - 63 lines]
> >
> > - Hide quoted text -

Signature

Dave Peterson

Gord Dibben - 26 Mar 2008 02:15 GMT
These I intend to scope out if I get an email.

Gord

>Or even a module named myMacro?
>Is the project named myMacro?
[quoted text clipped - 66 lines]
>> >
>> > - Hide quoted text -
Bernie Deitrick - 13 Feb 2008 18:16 GMT
Sheldon,

You will need to remove this part:

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
  On Error GoTo NotThere
  Application.CommandBars("My Bar").Visible = True
  Exit Sub
NotThere:
  CreateCommandbar
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
  On Error Resume Next
  Application.CommandBars("My Bar").Visible = False
End Sub

Then the commandbar will always be available to any workbook.

HTH,
Bernie
MS Excel MVP

> Thanks for the suggestion Bernie.  One thing I neglected to mention is
> that the macro I wrote would be run from any number of spreadsheets so
[quoted text clipped - 5 lines]
> the 3-4 users would still be very happy anyway.
> Sheldon Potolsky

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.