I was wondering if there was a way to run a VBA script when I open a sheet in the workbook.
For example, I have a workbook called "Inventory" and I want to run an "InitiateInventoryValues" Function when the "View Inventory" sheet is opened.
Can anybody please help me on this?
Click Developer > Visual Basic. In the VBA Project Explorer on the left hand side, expand the VBA Project folder for your workbook, then double-click the ThisWorkbook module. Paste your recorded code in the Sub procedure between the Sub and End Sub lines. Close the Visual Basic Editor (you don't have to save anything).
Double click the "Workbook" icon in VBE and use this event. It will trigger everytime you activate a different sheet by clicking its tab. If the tab is the one named "View Inventory", your code will run (once) when the sheet is activated:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "View Inventory" Then
'Do your code
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With