Run VBA on Hidden Sheets

mtagliaferri

Board Regular
Joined
Oct 27, 2004
Messages
156
I have a code which works perfectly, I need to refine the UI experience and need to hide the sheets to sheets the code runs on, of course the code wont run, so I thought to make the individual sheet visible to run the code and then hide it again.
I have tried a few variants of the below code (Worksheets / Sheets) I have also placed the code after the "With ShAcceptanceOfResignation" but everything I try gets me knowhere!

VBA Code:
Sub CreateOpenPDF()

    Application.ScreenUpdating = False
    
    Worksheets("ShAcceptanceOfResignation").Visible = True
    With ShAcceptanceOfResignation
        .ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\Documents\" & .Range("B16") & " " & .Range("B17") & " " & _
         Format(.Range("M26"), "YYYYMMDD") & " " & .Name & ".pdf", OpenAfterPublish:=True
   Worksheets("ShAcceptanceOfResignation").Visible = False
    End With
    
    With ShLeaversForm
        .ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\Documents\" & .Range("D12") & " " & .Range("D13") & " " & _
         Format(.Range("E19"), "YYYYMMDD") & " " & .Name & ".pdf", OpenAfterPublish:=True
         
    End With
       
     With ShCompanyPropertyChecklist
        .ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\Documents\" & .Range("D11") & " " & .Range("D12") & " " & _
         Format(.Range("J13"), "YYYYMMDD") & " " & .Name & ".pdf", OpenAfterPublish:=True
         
    End With
     
    Application.ScreenUpdating = True
    
  End Sub

What am I doing wrong?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What is happening currently with that code?
 
Upvote 0

Attachments

  • Capture.JPG
    Capture.JPG
    104 KB · Views: 8
Upvote 0
Then you don't have a sheet with that name. If it's a code name, use:

Code:
ShAcceptanceOfResignation.Visible = True
 
Upvote 0
Solution

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top