Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro not autorunning upon open

Tags:

excel

vba

Private Sub Workbook_Open()
Dim WB As Workbook

Set WB = ActiveWorkbook


WB.Sheets("Automation").Range("U23:W467").Select

Selection.ClearContents

End Sub

From what I can gather from SO, this code should automatically clear contents in those cells when I open the workbook. However, it doesn't. When I step into the code everything works fine and the cells are cleared.

Any help is appreciated!

like image 538
Daruki Avatar asked Mar 14 '23 23:03

Daruki


1 Answers

Where is the code for sub Workbook_Open() placed?

If you put it in the ThisWorkbook class it should run.

If you have it in a regular code module it will not run with that name, but you could call the sub Auto_Open() instead and it should run automatically.

like image 128
Olle Sjögren Avatar answered Mar 24 '23 19:03

Olle Sjögren