How do I initiate a Visual Basic Module in Excel?

G

Guest

I've created macros with Excel (or Visual Basic?) recording keystrokes/mouse
clicks, but I've never interacted with VB directly.

I want to add a time / date stamp in a worksheet that will change each time
I save a workbook.

Not even sure where to begin.
 
G

Guest

To get to the Visual Basic Editor go to the Tools Menu/Macro/Visual Basic
Editor (or press Alt F11). Inside the Visual Basic Editor go to the Insert
Menu and select Module. This will add a code module to your workbook. In
the code module you can start a visual basic sub routine by typing code like
the following (or just copy and past this code):

Sub SetFooterHeaders()
Dim sht As WorkSheet

For Each sht In ThisWorkBook.Sheets
sht.PageSetup.CenterHeader = sht.Name
sht.PageSetup.RightFooter = "Run Date: " & Date
Next

End Sub

Now, when you go back to the worksheet, click on Tools/Macro/Macros and you
will see your subroutine "SetFooterHeaders" listed in the Macros list.
Select your macro and click on the Run button. The macro above will iterated
(loop) through all the sheets in your workbook and add the sheet name to the
respective sheet header and Today's Date as the footer. Date is a built-in
Visual Basic function that returns Today's Date. You can now go into the
PrintPreview screen and see your Headers and footers for each sheet. Note:
you could also run the code above from the Visual Basic Editor by placing the
mouse cursor anywhere inside the subroutine and pressing the F5 key.

Rich
 
W

watermt

Bob,
I realize your initial post to Bill's question was many years ago, but I'd
like to say that I am very greatful to you and all the contributors out there
as well as the moderators of the Microsoft Discussion Groups! And just why
am I so happy, well I find myself in Bill's shoes at this point in having a
need to learn how to initiate a VB module within Excel 2003. I've posted a
few questions over the last two months or so and just recently one regarding
the use of a Drop-Down Combo box. I have no clue as to how to do this, but .
.. .

Your suggestion to view Chip's website just may be what I need to get
started, I thank you and the site moderators for keeping posts like this one
available over the years!

Mike
 

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