+ Reply to Thread
Results 1 to 3 of 3

Run Macro Only On Visible Worksheet

  1. #1
    Registered User
    Join Date
    06-11-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    2

    Run Macro Only On Visible Worksheet

    I have a file that has multiple worksheets with some of the worksheets visible and some of the worksheets hidden. I want a macro to run only on the visible worksheets and to ignore the hidden worksheets. The macro below is supposed to create a header on all the sheets in the workbook that combines the file name with information from cell C1 of the tab titled Productivity and then add the worksheet name on a new line. Right now my macro runs on all the sheets in my workbooks, both visible and hidden, but I only want it to run on visible sheets. Any help would be appreciated.


    Sub Workbook_BeforePrint()
    Dim ws As Worksheet, wsT As Worksheet
    Set wsT = Sheets("Productivity")
    For Each ws In Worksheets
    ws.PageSetup.CenterHeader = "&f " & wsT.Range("C1").Value & Chr(13) & "&a"
    Next ws
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Run Macro Only On Visible Worksheet

    Hi, Emily03,

    if the code is placed in ThisWorkbook it should read like
    Please Login or Register  to view this content.
    Please note that you should use code-tags for displaying procedures.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    06-11-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Run Macro Only On Visible Worksheet

    Sorry for the late response, but thank you so much. It was just what I was looking for.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1