INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

Excel How To

So where exactly do I put this macro code then?? by KenWright
Posted: 16 Mar 05 (Edited 16 Mar 05)

If you've been given some code, but are unsure as to where to put it, then try this step by step guide, and it can be applied to almost any macro you see (Not all eg Event macros, but probably most):-

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

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.

Right click on the where it says VBAProject(Your_Filename) and choose 'Insert Module' and it will now look like this

VBAProject(Your_Filename)
   Microsoft Excel Objects
        Sheet1(Sheet1)
        Sheet2(Sheet2)
        Sheet3(Sheet3)
        ThisWorkbook
   Modules
        Module1

Double click the Module1 bit and then paste in whatever code you have been given, starting with the Sub xyz() bit and finishing at the End Sub bit, eg:-

CODE

Sub xyz()

    Dim ....blah blah blah
    Dim ....blah blah blah
        Code to do stuff

End Sub
Then hit File / Close and return to Microsoft Excel and save the file.  Now just do Tools / Macro / Macros / xyz


If you then wanted to get rid of the macro for any reason, then do the following:-

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)
        etc..........................
        ThisWorkbook
   Modules
        Module1

Right click on the Module1 and select remove.  When prompted with a question re exporting, just hit no.  Then hit File / Close and return to Microsoft Excel and save the file.

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close