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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA footer 2 entries required

Status
Not open for further replies.

Hayton

Technical User
Oct 17, 2001
257
NZ
Hi Guys I have this code to insert data into the footer of an Excel Worksheet.

With Worksheets("Dashboard").PageSetup
.CenterFooter = "&""Tahoma,Regular""&8""© Company Name " & Year(Now())
.CenterFooter = "&""Tahoma,Regular""&8""Page &P of &N"
End With

However it does not insert both lines. it only inserts the last line "Page &P pf &N".

Is there a way I can get both lines inserted into the footer.

Any advice will be appreciated.

Hayton McGregor

 
I am not sure but I think you need to specify both lines as one string with a carriage return (chr(10)). Something like:
.CenterFooter = String1 & chr(10) & String2

_________________
Bob Rashkin
 
Bong is correct.

You can use
.CenterFooter = "text" & Chr(10) & "string"
or
.CenterFooter = "text" & vbLf & "string"

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Thanks Guys problem solved.

However there is an open speachmarks being inserted at the start of the string, eg: "Page 1 of 10.

I have tried delting various speach marks in the script and get a compile error.

Coulg you please see if you spot what I am doing wrong.

Cheers

Hayton McGregor

 
.CenterFooter = "&""Tahoma,Regular""&8© Company Name " & _
Year(Now()) & Chr(10) & "Page &P of &N"

BTW, you could easily get this code by using the macro recorder and typing a two-line footer. All you need to add to the recorded code is "Year(Now())".

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
You don't show your final code but in your original post you have an extra set of "double quotes" ...

.CenterFooter = "&[red]""[/red]Tahoma,Regular[red]""[/red]&8[red]""[/red]Page &P of &N"

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thanks Guys, i have used the record macro suggestion and all is well.

Cheers

Hayton McGregor

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top