Normal Topic Totally OT: Excel macro question (Read 4998 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Totally OT: Excel macro question
Aug 29th, 2007 at 2:21pm
Print Post Print Post  
I've never used Excel macros, but I've stumbled across some macro code that looks very useful.  So far I've been able to open the VB editor, paste the code, return to Excel, and run the macro.  Great, as far as it goes.  However, I see no way to "save" the macro for future use in new spreadsheets (when I close and reopen Excel, the macro does not appear in the list of macros available to run).

I'm using Excel 2003.  My macro security level has been set to "medium".

If anyone has experience with this, please hit me with a clue-by-four.  Thanks.
  

**
Captain Infinity
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Totally OT: Excel macro question
Reply #1 - Aug 29th, 2007 at 3:18pm
Print Post Print Post  
I don't have 2003 installed anymore, but I think the steps are to go to Tools, Macro, Macros (or Alt +F8) and type in a name of the new macro.  The VB editor will open and then you can paste the code in.  It should be saved with the spreadsheet then.

Hope my memory serves you well.
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Totally OT: Excel macro question
Reply #2 - Aug 29th, 2007 at 6:41pm
Print Post Print Post  
Hi Scott ...

To copy an Excel 2003 macro module to another workbook   

A.  Set the security level to Medium.  It sounds like you already did that.  If you need to change it, do this:
     1. On the Tools menu, click Options.
     2. Click the Security tab.
     3. Under Macro Security, click Macro Security.
     4. Click the Security Level tab, and then select the security level you want to use.

B.  Open the workbook that contains the module you want to copy and the workbook you want to copy the module to.

C.  On the Tools menu, point to Macro, and then click Visual Basic Editor.

D.  On the View menu, click Project Explorer .

E.  Drag the module you want to copy to the destination workbook.
---------------------------------------------------------------
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Totally OT: Excel macro question
Reply #3 - Aug 30th, 2007 at 4:32pm
Print Post Print Post  
Thanks for the suggestions, guys.  After a bunch of research I found that, for Excel macros to be shared across all workbooks, they have to be saved to a spreadsheet called Personal.xls, which resides as a "hidden" workbook in a folder called XLSTART in the Excel application data folder.  (So, for example, in my case it's "C:\Documents and Settings\Scott\Application Data\Microsoft\Excel\XLSTART\personal.xls".)

Now this is all well and good if you're performing a "record macro" routine, but if you have a bunch of VB code that you want to just paste and save, you have to jump through hoops.  First I had to open a blank workbook and "record a macro" (no keystrokes, just start the recording and end it) and tell Excel I wanted to save it in Personal.xls.  Then I had to open Personal.xls and "unhide" the workbook.  Only THEN could I open the macro for editing and paste the code, then I had to "hide" Personal.xls again, then save it to disk.

Once all that was done, the macro was available whenever I opened a new workbook in Excel.  The first time I forgot to "hide" Personal.xls, so that every time I fired up Excel, Personal.xls came up as the default workbook (instead of the usual "Book1.xls".)  Not really a problem because I "save as" and rename every new spreadsheet I create, but it bugged me that it mutated like that.

So there we go, what a pain, but it taught me how to fish, so I'll eat for a lifetime.  In the future I'll just edit Personal.xls directly.  Thanks again for the suggestions.
  

**
Captain Infinity
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Totally OT: Excel macro question
Reply #4 - Aug 30th, 2007 at 11:34pm
Print Post Print Post  
No need to create that other hidden personal spreadsheet if you have any spreadsheet with the macro you want.  As noted in my earlier posting, just open that sheet and using the VB editor, copy the module you want to the new spreadsheet you want. 

The personal.xls technique you mentioned is a good way though to keep a library of standard macros that you want use.  If you open that each time you start Excel you will be able to pick for macros in current open workbooks.  But you may want the macro embedded in the spreadsheet so you don't need to send a copy of the hidden workbook it you distribute the spreadsheet file.  I would suggest that you save macros that you want in personal.xls, but actually copy the module into the current workbook so it will be embedded. 

But like many programming issues, there are many ways to do the same thing, so use the method that works best for you,
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Totally OT: Excel macro question
Reply #5 - Aug 31st, 2007 at 12:17am
Print Post Print Post  
Quote:
But you may want the macro embedded in the spreadsheet so you don't need to send a copy of the hidden workbook it you distribute the spreadsheet file.

Good point, thanks.
  

**
Captain Infinity
Back to top
IP Logged