Getting this error when trying to unhide all sheets?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have this code:

VBA Code:
Sub unHide_Every_Sheet()
Application.EnableEvents = False
Application.ScreenUpdating = False

For Each sht In ActiveWorkbook.Worksheets
    If sht.Visible = xlSheetHidden Then
        sht.Visible = xlSheetVisible
    End If
Next sht

Sheets("Control").Select

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

it works great on my PC buy my cloeges Surface pro just give us this run time error

run-time error '-2147417848 (80010108)
method visible of object _worksheet failed

the strange thing is it doesnt do it every time but after two or three run it does then might be like it for ages,
I get this error then the computer freezes and i have to hit Ctrl alt Del to get out or it just crashes and closes down.

I cant work out why?
i have tried running the macro stoped and preeessing F8 and it runs all the way without an error

does anyone know why it might be doing this?
what i can try to fix it

It run perfectly on my machine?

thanks

Tony
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try it without Application.EnableEvents = False
Make sure the sheets aren't protected OR xlVeryHidden
 
Upvote 0
Hi Michael,
I have tried everything i can think of including the above,
the strandes part is i've even completly changed the macro so it was just unhiding each sheet by name and i still go the same problem.
I'm thinking its more to do with his computer, maybe a feature or a seeting that I take for granted is not there or switched off, but i dont know where to look and i've done all the standard things?
Its very perplexing
 
Upvote 0
Maybe
ActiveWorkbook.Worksheets should be ThisWorkbook.Worksheets

and
Sheets("Control").Select should be ThisWorkbook.Sheets("Control").Select
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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