Run-time error '1004' on WB open [VBA]

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi team,

down below is the code that runs on WB open.

Every time I open that Workbook I am getting a Run-time error '1004'.

Untitled.png


What could be the cause?

Thank you for help.

VBA Code:
Private Sub Workbook_Open()

With Application
.ScreenUpdating = False: .WindowState = xlMaximized: .DisplayStatusBar = True

Call OptimizeCode_Begin

Worksheets("WELCOME").Activate
With ActiveWindow
Worksheets("WELCOME").Range("A1:AD1").Select
.DisplayHorizontalScrollBar = False: .DisplayVerticalScrollBar = False: .DisplayWorkbookTabs = False: .ZOOM = True: .ScrollRow = 1: .ScrollColumn = 1
Worksheets("WELCOME").Range("A1").Select
End With

Call OptimizeCode_End

.ScreenUpdating = True
End With

End Sub

VBA Code:
Public CalcState As Long
Public EventState As Boolean
Public PageBreakState As Boolean

Sub OptimizeCode_Begin()
EventState = Application.EnableEvents
Application.EnableEvents = False
CalcState = Application.Calculation
Application.Calculation = xlCalculationManual
Application.DisplayFormulaBar = False
PageBreakState = ActiveSheet.DisplayPageBreaks
ActiveSheet.DisplayPageBreaks = False
End Sub

Sub OptimizeCode_End()
ActiveSheet.DisplayPageBreaks = PageBreakState
With Application
.Calculation = CalcState: .Calculation = xlCalculationAutomatic: .EnableEvents = EventState: .EnableEvents = True
End With
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The first thing we should do is find out exactly what line of code is causing the error.
Place your cursor anywhere on the first line "Private Sub Workbook_Open()" and press the F8 key.
This should highlight the first line yellow, as you step into the code to run it line-by-line.
As you press F8, each time it will run the next line of code.
Keep pressing F8 until you get the error, and let us know which line of code it was on when the error occurred.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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