VBA Help w Hidden Page

TAEMEXICO

New Member
Joined
Nov 7, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Yes, I know how to unhide multiple hidden pages using a For Next loop. When seems to have me stumped is how to check if a single, specific page is hidden or not?

Regardless of rather sheet "Tiger" is hidden or not, nothing between the IF/END IF works! So clearly my code is not able to actually verify if the specific sheet is visible or not. Any help much appreciated, thx.

VBA Code:
Dim exportWB As Excel.Workbook
Set exportWB = Workbooks.Open(StrFile)

exportWB.Activate
Worksheets("Tiger").Activate

If Sheets("Tiger").Visible = True Then
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I don't think that you can Activate a hidden Sheet. Try this:
VBA Code:
Dim exportWB As Excel.Workbook
Set exportWB = Workbooks.Open(StrFile)
Dim sht as Worksheet 
Set sht = exportWB.Sheets("Tiger")
If sht.Visible = True Then
 
Upvote 0
Solution
IDK WTF but now my code I've literally been using over 8 years now suddenly won't work and I didn't change anything at all. I made a slight alteration to that bit you presented, then the saved portion borked completely. So I literally just STEP INTO till I saw where it crashed and it wasn't at the section I added, but the SAVE FILE portion I haven't altered in eons. Regardless, I commented out the new addition just to be safe and it keeps giving me this error... so I can't even tell you yet if those changes you suggested work or not!

ERROR # -2147018887
Document not saved.

RED Portion suddenly stopped working. Maybe a Window 10 update? Again...

Rich (BB code):
    importWB.Activate
    Call ProtectSheet
    
    exportWB.Activate
    mySaveAs = ActiveWorkbook.Name
    mySaveAs = Left(mySaveAs, InStr(1, mySaveAs, " (") - 1)
    importWB.Activate
    
    ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\" & mySaveAs & " " & myVer, Quality:=xlQualityStandard, OpenAfterPublish:=False 'True
    ActiveWorkbook.SaveCopyAs Filename:=ActiveWorkbook.Path & "\" & mySaveAs & " (" & myVer & ").xlsm"
    
    exportWB.Close SaveChanges:=False
    importWB.Sheets("INSTINCT.COVER").Activate
 
Upvote 0
I'm not sure what your ProtectSheet Sub does, so I'm not sure I can be much help but.... I try to make a habit of not using ActiveWorkbook or ActiveSheet if I have more than one Workbook open. Since you have already assigned your variables try getting rid of them. i.e. -


VBA Code:
Call ProtectSheet
   
    exportWB.Activate  'Remove this line
    mySaveAs = exportWB.Name
    mySaveAs = Left(mySaveAs, InStr(1, mySaveAs, " (") - 1)
    importWB.Activate 'Remove this line
   
    importWB.ExportAsFixedFormat Type:=xlTypePDF, Filename:=importWB.Path & "\" & mySaveAs & " " & myVer, Quality:=xlQualityStandard, OpenAfterPublish:=False 'True
    importWB.SaveCopyAs Filename:=importWB.Path & "\" & mySaveAs & " (" & myVer & ").xlsm"
   
    exportWB.Close SaveChanges:=False
 
Upvote 0
IDK how to go back and edit posts on these forums. Anyway, my comp needed a reboot and the code started working again. Sometimes it's the little things... Oh, and more importantly, your suggestion worked so all is well!
 
Upvote 0
I'm not sure what your ProtectSheet Sub does, so I'm not sure I can be much help but.... I try to make a habit of not using ActiveWorkbook or ActiveSheet if I have more than one Workbook open. Since you have already assigned your variables try getting rid of them. i.e. -


VBA Code:
Call ProtectSheet
   
    exportWB.Activate  'Remove this line
    mySaveAs = exportWB.Name
    mySaveAs = Left(mySaveAs, InStr(1, mySaveAs, " (") - 1)
    importWB.Activate 'Remove this line
   
    importWB.ExportAsFixedFormat Type:=xlTypePDF, Filename:=importWB.Path & "\" & mySaveAs & " " & myVer, Quality:=xlQualityStandard, OpenAfterPublish:=False 'True
    importWB.SaveCopyAs Filename:=importWB.Path & "\" & mySaveAs & " (" & myVer & ").xlsm"
   
    exportWB.Close SaveChanges:=False
Thanks, it ended up being so stupid... you know, like resetting a phone/tablet that's crapping out? I just rebooted my computer and everything worked! My guess is I had that document open in memory for like 5-days and some update make things screwey. Anyway, all is good now, and thank you for trying to help me with my issue! I do appreciate it!
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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