Headers and Footers in VBA

J

JacMar

I use Excel 2002. I recently got info from this group about printing headers
and footers on selected pages, and it worked very well. Now my question is;
How do I specify a multi line header (of footer), in a format similar to an
address, ie:

Name
Street address
City, State
Zip Code

I have not been able to find code to force a Carriage Return.

Thanks in advance
 
B

Bob Phillips

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
.LeftHeader = "Line 1" & vbCr & "Line 2"
End With
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
J

JacMar

Thanks Bob Phillips: this helped a lot. But I have now discovered a couple
other problems: The setup is as follows: I have a logo (picture) to print
as a left header. It works. Then I want to print the complete address, to
the right of that left header. I tried to use CenterHeader for that. But it
prints the multi lines of text with a "center" format. I'd like it to be
left justified. If I use "&L", it justifies it to the left of the sheet of
paper, and writes over the logo. I thought that LeftHeader, CenterHeader and
Right Header divided the page in three seperate regions. It seems not.

How can I left justify multiline text, to the right of my LeftFooter logo?

I would also like to add text (Annex "X" to Contract "Y" for example), under
the picture logo, left justified to the page. If I use LeftHeader, it writes
it top left and the picture logo dissappears. If I use CenterHeader, put a
bunch of blank lines and then asks that the text be left justified, it
overwrites the logo on the top left, seemingly ignoring the blank lines.

How do I do it.

Thanks again, you have all been very helpful
 
B

Bob Phillips

On the first point, text in the centre heading area is centred, and I don't
know how to avoid that.

Perhaps you could put the address in the left header and the picture centred
or right, or put the address in the right header, it will be right aligned,
but that won't be as bad as centre aligned.

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
J

JacMar

Thanks. Actually, plan B was to put the address as a RightHeader. How about
my second question: where I have not been able to put text under the picture
logo? Because the data in this text will change, I cannot incorporate it in
the picture logo. Any suggestions?

Thanks again
 

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