I want to initialize some variable (like the ranges for graphs) in the Workbook_Open function in ThisWorksheet. This is done like:
Public ChartSizePosition As Range
Sub Workbook_Open()
Set ChartSizePosition = Range("B8:I25")
Worksheets("Übersicht").Range("A1").Value = "q3f"
End Sub
Afterwards I want to access the variable from some Sub in a module. But there is always given an error "Runtime error 424. Object necessary". The Workbook_Open code is definitely reached.
Anyone can give me a suggestion?
Best regards and thanks!
If you add a public variable to a class module (which ThisWorkbook is) you have to refer to the variable as a member of that class. So you have to refer to ThisWorkbook.ChartSizePosition
rather than just ChartSizePosition
.
Alternatively you can move the declaration to a normal module.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.