Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
VBA - The Excel Working Partner
Record a Code Sample For Yourself
 More of this Feature
• Part 1: Using VBA with Microsoft Excel
• Part 3: Learning From Your Code Sample
• Part 4: Customizing the Personal Workbook
 
 Join the Discussion
Do you use Excel VBA?
Tell us how !
 
 Related Resources
• Beginning Visual Basic
• Visual Basic 6
 
 From Other Guides
• About Business Software
 
 Elsewhere on the Web
• An Excel VBA book
From the great publisher, APress

• Excel Updates from Microsoft
(Browse to Office 2000)

 

Let's write a program that creates a new customized worksheet automatically to see how this works. I created a background graphic that I want to be used as a background for my new customized worksheet (it's in the file download at the end of the article). I also want to save my customized workbook with a different default name in a specific location.

  • Select Personal Macro Workbook to start the Recorder so you can go through the steps of customizing a worksheet and saving it while those steps are being recorded.
  • Select Format > Sheet > Background and browse to the graphic file that you want to be used as a background.
  • Select File > Save As and browse to the folder that you want to use to save your customized workbook. Give the file a new name before saving it. I used the file name AboutWB.xls. Later, we'll show you how to change this name inside the VBA program.
  • Click the Stop button to stop the Recorder. (If you have configured your system so the Stop Recording toolbar isn't visible, you might have to select Tools > Macro > Stop Recording from the menu.)

Also, remember to click Yes when Excel asks you whether you want to save the Personal.xls workbook when you close Excel.

Now let's examine the VBA program that has been recorded. Select Tools > Macro > Visual Basic Editor and click Module1 under Personal.XLS to display the VBA code window. (You might have to click the View Code button in the upper left corner to display the code. Also note that if you try to edit the VBA program by selecting Macro and then clicking the Edit button, an error message is displayed that tells you that you can't edit a macro on a hidden workbook. Why VBA has these inconsistencies in it is beyond my understanding!)

Excel Visual Basic Editor

Next page > Learning From Your Code Sample > Page 1, 2, 3, 4

Explore Visual Basic

By Category

About.com Special Features

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.