PC Review


Reply
Thread Tools Rate Thread

CenterHeader, RightHeader, LeftHeader

 
 
Ross Culver
Guest
Posts: n/a
 
      11th Oct 2007
I have the following code:

With Worksheets("Report").PageSetup
.RightHeader = xRightHeader
.CenterHeader = xCenterHeader
.LeftHeader = xLeftHeader
End With

The xVariables are defined and populated just prior to this code.

I get the following error: Run-time error '1004' "Unable to set the
LeftHeader property of the PageSetup class".

If I swap the code around like this:

With Worksheets("Report").PageSetup
.RightHeader = xRightHeader
.CenterHeader = xCenterHeader
.LeftHeader = xLeftHeader
End With

I get: Run-time error '1004' "Unable to set the RightHeader property of the
PageSetup class".

If I remove either the right, the left or the center, the code works fine.
Is there some kind of limitation that prevents us from setting all three of
the headers?

Ross


 
Reply With Quote
 
 
 
 
Bill Renaud
Guest
Posts: n/a
 
      12th Oct 2007
I don't see any difference in your 2 versions of your code. The following
demo code worked fine for me (Excel 2000), even if I set one of them to a
blank string (""):

Public Sub Test()
Const xLeftHeader = "&F"
Const xCenterHeader = "&T"
Const xRightHeader = "&D"

With Worksheets("Report").PageSetup
.RightHeader = xRightHeader
.CenterHeader = xCenterHeader
.LeftHeader = xLeftHeader
End With
End Sub

Usually when I start having these kind of problems, I back up and declare
object variables, so that I can step through the code and verify
everything. In other words, try the following:

Public Sub Test()
Const xLeftHeader = ""
Const xCenterHeader = "&T"
Const xRightHeader = "&D"
Dim wsReport As Worksheet

Set wsReport = ActiveWorkbook.Worksheets("Report")

With wsReport.PageSetup
.RightHeader = xRightHeader
.CenterHeader = xCenterHeader
.LeftHeader = xLeftHeader
End With
End Sub

It may be time to clear the symbol tables by exporting all of your code
modules and worksheet event handlers, saving the workbook without any code,
then re-importing and recompiling the project. After lots of editing (and
variable name changes, etc.), VBA can get confused sometimes.

<<Is there some kind of limitation that prevents us from setting all three
of the headers?>>

Not that I know of. What version of Excel are you running?

--
Regards,
Bill Renaud



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change jpeg Picture in LeftHeader Ryan H Microsoft Excel Programming 2 8th Dec 2009 08:49 PM
Using VBA to insert a multiple-row title in the CenterHeader =?Utf-8?B?TW9udGFuYQ==?= Microsoft Excel Programming 2 18th Oct 2006 03:02 PM
Setting LeftHeader / CenterHeader MBaas Microsoft Excel Programming 3 17th Aug 2006 04:56 PM
VBA Code to Print a Variable as part of CenterHeader Problem gvlral Microsoft Excel Programming 2 30th Jan 2005 06:27 PM
Excel generation and PageSetup.CenterHeader lfb Microsoft Excel Programming 3 9th Feb 2004 05:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:13 PM.