ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I initiate a Visual Basic Module in Excel? (https://www.excelbanter.com/excel-programming/329255-how-do-i-initiate-visual-basic-module-excel.html)

Bill

How do I initiate a Visual Basic Module in Excel?
 
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.
--
Thanks,Bill

Rich

How do I initiate a Visual Basic Module in Excel?
 
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

"Bill" wrote:

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.
--
Thanks,Bill


Bob Phillips[_7_]

How do I initiate a Visual Basic Module in Excel?
 
Bill,

You are entering the realm of events, and you are not yet properly ordained
:-).

Have a look at Chip's site for some pointers
http://www.cpearson.com/excel/events.htm

--
HTH

Bob Phillips

"Bill" wrote in message
...
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.
--
Thanks,Bill




watermt

How do I initiate a Visual Basic Module in Excel?
 
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

"Bob Phillips" wrote:

Bill,

You are entering the realm of events, and you are not yet properly ordained
:-).

Have a look at Chip's site for some pointers
http://www.cpearson.com/excel/events.htm

--
HTH

Bob Phillips

"Bill" wrote in message
...
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.
--
Thanks,Bill






All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com