Separate Macro from Workbook

J

jswalsh33

In response to a question on allowing a macro to be available for all files
in Excel dated 5/17/09, FST1 wrote a solution that did what was requested.

Namely:
C:\Program Files\Microsoft Office\Office12\XLSTART (i think).
The file will open automaticly(hidden) when excel starts and all macros in
the personal.xlsb will be available for use on all files.

My question is can the same be done for certain Excel workbooks but not
others?

Any help will be greatly appreciated.

Jim Walsh
 
F

FSt1

hi
you seem to have two questions.
subject:Separate macro from workbook.
no. can't be done.
not sure about your second question. if it's in the xls start folder, it
will open with excel and all macros in the open workbooks can be use on other
files provided they are generic ie make no reference to a specific workbook
name or worksheet name.

if i didn't answer your question, post back with more detail.

Regards
FSt1
 
J

jswalsh33

You answered the real question, which was can the macros and the workbook be
separated.

What I was trying to do was to save changes in the workbook and not save
changes in the macros.

Any ideas on that one?

Thanks,

Jim Walsh
 
F

FSt1

hi
no really. the vb part and the file are intergrated. saving saves all. if
there is a way around it, i don't know it.

Regards
FSt1
 
G

Gord Dibben

Been following this and not sure what OP is after.

First talks about Personal Macro Workbook being in XLSTART folder and
opening hidden, then asks "can the same be done for certain Excel workbooks
but not others?"

Does OP want to have more workbooks in XLSTART folder that open hidden?

Yes is the answer to that.

Does OP want some macros available for some workbooks but not have
Personal.xls open all the time.

Also Yes to that.

Can you have macros in a workbook and save the workbook and delete the
macros when saving.

Yes to that also.

OP needs to describe needs in more detail.


Gord Dibben MS Excel MVP
 
G

Gord Dibben

Having a "control person" leads me to believe you're on a network.

True?

You may be best off in that case to put all the macros in a new workbook
then save it as an addin stored where all users have access.

No need for any macros in the database workbooks that users are working on
and any updates/changes to the add-in are only done in one place.

Unless you wanted some workbook_open code in the DB workbooks to load the
add-in for each user when they open their copy of DB workbook.

Private Sub Workbook_Open()
AddIns("addin_name").Installed = True
End Sub

Then unload when workbook is closed if you wish.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
AddIns("addin_name").Installed = False
End Sub

Or just rely on users to load the add-in themselves.


Gord
 
J

jswalsh33

Gord,

Thanks again,

I think what you suggest will do the job. The program may or may not be on a
network.

I will give it a try and let you know how I make out. I am not quite sure
how to save a workbook as an "add-in, but I will try to figure it out.

Jim Walsh
 
J

jswalsh33

Gord,

I loaded your suggestion and was able save the add-in, bring up the add-in
when I opened the Worksheet with the databases and de-load the add-in when
the workbook is closed. I can see the macros in the macro list of the add-in.

However, I am missing something. I cannot run the macros from the database
workbook. I get a message that the program can't find the macro I am trying
to run. The macros are called by command buttons in the database workbook.

Help?

Thanks,

Jim Walsh
 
G

Gord Dibben

With both the db workbook and the addin open go to VBE and select db
workbook.

Tools>References.

Select the add-in name.

Now click a command button.

If no joy and I can't see why you would have no joy, you can always use
Application.Run in your command button code.

Application.Run ("MyMacros.xla!macroname")


Gord
 

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