Ask Experts Questions for FREE Help !
Ask
    adalton's Avatar
    adalton Posts: 22, Reputation: 1
    New Member
     
    #1

    Jul 27, 2009, 03:14 PM
    Looping Through Sheets
    Is there a way to loop through sheets in a workbook. I would like to add a header/footer to each sheet in a workbook and then apply the header/footer macro to each sheet.
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Jul 27, 2009, 05:37 PM

    Here's a sample to whet your appetite, you can adjust/play from there:
    Code:
    Sub InsertHeaderFooter()
    ' inserts the same header/footer in all worksheets
    Dim ws As Worksheet
        Application.ScreenUpdating = False
        For Each ws In ActiveWorkbook.Worksheets
            Application.StatusBar = "Changing header/footer in " & ws.Name
            With ws.PageSetup
                .LeftHeader = "Company name"
                .CenterHeader = "Page &P of &N"
                .RightHeader = "Printed &D &T"
                .LeftFooter = "Path : " & ActiveWorkbook.Path
                .CenterFooter = "Workbook name &F"
                .RightFooter = "Sheet name &A"
            End With
        Next ws
        Set ws = Nothing
        Application.StatusBar = False
    End Sub
    (source)

    Or...
    Code:
    Sub setFooter()
        Dim mySht As Variant
    
        For Each mySht In Worksheets
            mySht.Activate
            ActiveSheet.PageSetup.LeftFooter = _
            Format(Worksheets("SetUp").Range("A1").Value)
            ActiveSheet.PageSetup.RightFooter = _
            Format(Worksheets("SetUp").Range("B1").Value, "mmddyy")
        Next
                
    End Sub
    (source)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Computer looping [ 7 Answers ]

I am having trouble. We did a complete reinstall on Windows 2000 Professional. It starts the window 2000 set up, but at a certain point,starts allover again loading windows 2000. Ive tried taking the disk out, but it just keeps asking me where to boot from. Here is some of the messages I've...

Need VBA syntax for looping through checkboxes with IF statements [ 7 Answers ]

The title explains it all. I need the command to loop through all of the checkboxes. There is also an IF command as well. Let me know! Rick


View more questions Search