Error in WorkBook_Open code: Activate method of Worksheet class failed

Gaurangg

Board Regular
Joined
Aug 6, 2015
Messages
134
Hi Falks,

I have written a code in workbook module in a file with Workbook_Open activity and I am receiving the below error while I am opening the file from sent email or sometimes from main file.

Can anyone help me to resolve the below error

------------------------------------------------------
Run-time error '1004':

Activate method of worksheet class failed
------------------------------------------------------

Code:
Private Sub Workbook_Open()
'Runs after Workbook is opened to unhide data sheets


    'Step 1: Ensure that START sheet is visible
    Sheets("START").Visible = xlSheetVisible
    
    'Step 2: Hide all other workSheets
    Sheets("Form_Input").Visible = xlVeryHidden
    Sheets("Form").Visible = xlVeryHidden
    Sheets("Collation").Visible = xlVeryHidden
    
    
    ThisWorkbook.Sheets("START").Activate
    Range("F9").Select
    Range("F9").ClearContents
    
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
If you hit the "debug" option on the error message that pops up, what line of code does it highlight?
 
Upvote 0
Please don't use Activate, nor Select. A better method:

Code:
'....
ThisWorkbook.Sheets("START").Range("F9").ClearContents
End Sub
 
Last edited:
Upvote 0
The issue may also be with "ThisWorkbook". You may want to try "ActiveWorkbook" instead.
Or better yet, leave it off altogether. I don't think it is necessary. By default, it will run against whatever the active workbook is at the time it hits that line of code.
 
Upvote 0
Hi Joe4,

After hitting the "debug' button, the below line gets highlighted-

ThisWorkbook.Sheets.("Start").Activate

Also I have checked with ActiveWorkbook event and got the error as below

Run-time error '91':

Object variable or With block variable not set
 
Last edited:
Upvote 0
Did you try what I suggested in my last post, and just change that line to:
Code:
[COLOR=#333333]Sheets.("Start").Activate[/COLOR]
 
Upvote 0
Can you confirm that the "START" sheet is indeed, visible, at that point?
 
Upvote 0
Yes. I have renamed the sheet with "Main" and it is visible although.

Currently I am using below code which is working "ok" but sometimes when It got crashed when I close the file after updating any data into the input sheet.

All the excels got closed after not responding for sometime. and asks that "Close the program". Can anyone help me where I am doing mistake in my code.

Code:
Private Sub Workbook_Open()
'Runs after Workbook is opened to unhide data sheets


    Dim WB As Workbook
    Set WB = ThisWorkbook
    'WB.Activate
    'Step 1: Ensure that START sheet is visible
    Sheets("MAIN").Visible = xlSheetVisible
    
    'Step 2: Hide all other workSheets
    Sheets("Audit Form_Input").Visible = xlVeryHidden
    Sheets("Audit Form").Visible = xlVeryHidden
    Sheets("Audit Collation").Visible = xlVeryHidden
    
    
    Sheets("MAIN").Visible = xlSheetVisible
    
    'Worksheets("MAIN").Activate
    ThisWorkbook.Sheets("MAIN").Range("F9").ClearContents
    'Sheets("START").Select
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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