Macro is not authorized at opening

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 compile from SO, this code should automatically clear the contents in those cells when I open the book. However, it is not. When I enter the code, everything works fine and the cells are cleared.

Any help is appreciated!

+4
source share
1 answer

Where is the code for sub located Workbook_Open()?

If you put it in a class ThisWorkbook, it should work.

If you use it in a regular code module, it will not work with this name, but instead you can call sub Auto_Open(), and it should start automatically.

+7
source

Source: https://habr.com/ru/post/1619084/


All Articles