Getting this error when trying to unhide all sheets?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,808
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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,880
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Try it without Application.EnableEvents = False
Make sure the sheets aren't protected OR xlVeryHidden
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,808
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
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
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,880
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
His PC might be a Mac..... :devilish:
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,306
Office Version
  1. 2016
Platform
  1. Windows
Maybe
ActiveWorkbook.Worksheets should be ThisWorkbook.Worksheets

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

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,808
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Thanks Michael but I dont think Apple make Surface Pros? LOL
 

Forum statistics

Threads
1,141,063
Messages
5,704,064
Members
421,326
Latest member
pfaustino

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
Top