Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba : Headers not displaying in all sheets

Have a workbook populated by several sheets copied from other book. After
they are copied, I loop thru the .Sheets collection, adding headers to each
sheet.
For some reason, the headers are only displaying on some sheets. Has anyone
ever run across this problem before? Sheet property that isn't set properly?
Any Ideas?

Thanks - Sean


Public Sub HeaderSet()
Dim sht As Worksheet

For Each sht In Workbooks(s_Author & ".xls").Sheets
If sht.Type = xlWorksheet Then
sht.PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
sht.PageSetup.CenterHeader = _
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
sht.PageSetup.RightHeader = "&D"
End If
Next sht

End Sub

also tried :

Public Sub HeaderSet()
Dim i As Integer

For i = 1 To Workbooks(s_Author & ".xls").Sheets.Count
If Workbooks(s_Author & ".xls").Sheets(i).Type = xlWorksheet Then

Workbooks(s_Author & ".xls").Sheets(i).PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
Workbooks(s_Author & ".xls").Sheets(i).PageSetup.CenterHeader =
_
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
Workbooks(s_Author & ".xls").Sheets(i).PageSetup.RightHeader =
"&D"
Else

Workbooks(s_Author & ".xls").Charts(i).PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
Workbooks(s_Author & ".xls").Charts(i).PageSetup.CenterHeader =
_
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
Workbooks(s_Author & ".xls").Charts(i).PageSetup.RightHeader =
"&D"
End If
Next i

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default vba : Headers not displaying in all sheets



Loop through the worksheets collection. If you are going to Dim sht as
Worksheet, there is no reason not to.

Public Sub HeaderSet()
Dim sht As Worksheet
Dim sh as Worksheet
set sh = Activesheet
For Each sht In Workbooks(s_Author & ".xls").WorkSheets
' added just to check what is in the collection
' that gets processed
msgbox Sht.Name & " is worksheet"
sht.Activate
sht.PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
sht.PageSetup.CenterHeader = _
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
sht.PageSetup.RightHeader = "&D"
Next sht
sh.Select
End Sub

--
Regards,
Tom Ogilvy


"SeanMc" wrote:

Have a workbook populated by several sheets copied from other book. After
they are copied, I loop thru the .Sheets collection, adding headers to each
sheet.
For some reason, the headers are only displaying on some sheets. Has anyone
ever run across this problem before? Sheet property that isn't set properly?
Any Ideas?

Thanks - Sean


Public Sub HeaderSet()
Dim sht As Worksheet

For Each sht In Workbooks(s_Author & ".xls").Sheets
If sht.Type = xlWorksheet Then
sht.PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
sht.PageSetup.CenterHeader = _
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
sht.PageSetup.RightHeader = "&D"
End If
Next sht

End Sub

also tried :

Public Sub HeaderSet()
Dim i As Integer

For i = 1 To Workbooks(s_Author & ".xls").Sheets.Count
If Workbooks(s_Author & ".xls").Sheets(i).Type = xlWorksheet Then

Workbooks(s_Author & ".xls").Sheets(i).PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
Workbooks(s_Author & ".xls").Sheets(i).PageSetup.CenterHeader =
_
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
Workbooks(s_Author & ".xls").Sheets(i).PageSetup.RightHeader =
"&D"
Else

Workbooks(s_Author & ".xls").Charts(i).PageSetup.LeftHeader = _
"Page No. " & "&P" & " of &N"
Workbooks(s_Author & ".xls").Charts(i).PageSetup.CenterHeader =
_
s_Author & Chr(10) & "&F" & Chr(10) & "&A"
Workbooks(s_Author & ".xls").Charts(i).PageSetup.RightHeader =
"&D"
End If
Next i

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Freeze column headers for ledger sheets Summer Excel Discussion (Misc queries) 0 April 30th 10 11:04 PM
can you set up global headers & footers for all sheets in a file? Donna Excel Discussion (Misc queries) 2 October 24th 08 07:05 PM
Can I duplicate headers and footers on multiple sheets? HeatherDBecerra Excel Worksheet Functions 2 April 13th 07 09:12 PM
how do i change headers on all workbook sheets globally? Muntly Excel Discussion (Misc queries) 2 March 13th 07 12:19 AM
how do I copy excel sheets with headers BJ Excel Worksheet Functions 1 February 15th 05 04:24 AM


All times are GMT +1. The time now is 04:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"