ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Headers and Footers in VBA (https://www.excelbanter.com/excel-discussion-misc-queries/127979-headers-footers-vba.html)

JacMar

Headers and Footers in VBA
 
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

Bob Phillips

Headers and Footers in VBA
 
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)

"JacMar" wrote in message
...
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




JacMar

Headers and Footers in VBA
 
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

"Bob Phillips" wrote:

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)

"JacMar" wrote in message
...
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





Bob Phillips

Headers and Footers in VBA
 
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)

"JacMar" wrote in message
...
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

"Bob Phillips" wrote:

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)

"JacMar" wrote in message
...
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







JacMar

Headers and Footers in VBA
 
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

"Bob Phillips" wrote:

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)




All times are GMT +1. The time now is 08:16 PM.

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