Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Header Code help needed 1

Status
Not open for further replies.

thevillageinn

Technical User
Feb 28, 2002
124
US
I'm attempting to adjust the header on my spreadsheet to display the value of a cell (A2 in this case).

I understand that I need to use the BeforePrint command, but I am stumped as to how to call it or name it or reference it so that it sets my header.

I am somewhat familiar with VBA in Access, but I'm having a hard time wrapping my mind around the Excel model.

my code currently looks like this:
Code:
Public Sub BeforePrint(Cancel As Integer)

Worksheets("Sheet1").PageSetup.LeftHeader = Worksheets("Sheet1").Range("A2")

End Sub

Thanks in advance for any assistance offered.
-Dan

 
The sub you are looking for is :
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

End Sub
However the location of this code is important. You must place it in the ThisWorkbook object of the relevant project.

Go to the VBA editor, and on thr rightt of the screen you should see a list of projects, such as Book1 etc. Select the one you are working with and double click on the item ThisWorkbook. Place your code in the resultant codepane.

A.C.
 
A.C.
Thank you very much. That works perfectly.
I guess I wasn't too far off, but I was getting frustrated.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top