Typing in macros

S

sue t

I have made a few macros and use them in word and excel
2000. When I see typed out macros on the message boards I
am not quite sure how to use them. Do I go into the
editor, type them in and then link them with a button on
the toolbar? What module do I put them in and is there
one for the personal worksheet. I have been struggling
with the syntax of Visual Basics for years. Just need a
step by step explanation.

Thank You Sue
 
K

Ken Wright

In general, the macros you see in the groups are likely to be ordinary macros
that will go into a general module in the VBE, eg:-

Hit ALT+F11 and this will open the VBE (Visual Basic Editor)
Top left you will hopefully see an explorer style pane. Within this pane you
need to search for
your workbook's name, and when you find it you may need to click on the + to
expand it. Within
that you should see the following:-

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
ThisWorkbook
Modules
Module1
Module2
etc etc (You may have just 1 or even none of these)

If you have named your sheets then those names will appear in the brackets above
as opposed to
what you see at the moment in my note. If you have no modules then rightclick
on the VBA Project bit and choose insert module. Then copy the routine from the
post, doubleclick the module and paste it into it. Now just hit File / Close
and return to Microsoft Excel and save the file.

You can now run the macro using Tools / Macro / Macros - Pick the name from the
list, OR by assigning it to a button as you said.

Event macros are slightly different and will go in either ThisWorkbook module or
one of the Sheet modules:-

http://cpearson.com/excel/events.htm
 
G

Gord Dibben

Sue

The macro code you see on the message board can most times be copied and
pasted to a module.

Which type of module depends upon the code. General code, worksheet_event
code, workbook_open code are all treated differently and are used for
different purposes.

Yes. You can copy/paste to your Personal.xls if the code is appropriate.

Visit David McRitchie's site for info on Getting Started with VBA and Macros.

Gord Dibben Excel MVP
 
Top