PDA

View Full Version : Solved: Activate Macro When Sheet is Opened?



doctortt
05-01-2011, 10:19 AM
Hi,

How do you make Excel to activate this IF statement when the VBA program is started?

If OptionButton1.Value = True Then
Showmethis 'this is the macro for launching something
End if

So whenever Excel detects the TRUE for this optionbutton1, it will launch "showmethis" which is the macro.

Bob Phillips
05-01-2011, 10:53 AM
Private Sub Workbook_Open()
If OptionButton1.Value = True Then
Showmethis 'this is the macro for launching something
End if
End Sub

This is workbook event code.
To input this code, right click on the Excel icon on the worksheet
(or next to the File menu if you maximise your workbooks),
select View Code from the menu, and paste the code

doctortt
05-01-2011, 01:05 PM
Private Sub Workbook_Open()
If OptionButton1.Value = True Then
Showmethis 'this is the macro for launching something
End if
End Sub

This is workbook event code.
To input this code, right click on the Excel icon on the worksheet
(or next to the File menu if you maximise your workbooks),
select View Code from the menu, and paste the code

HI, I did paste the code then saved the excel file. However, when I open the excel file, "showmethis" doesn't launch. =(

Why?

Aussiebear
05-01-2011, 03:21 PM
Did you paste the code into the ThisWorkbook module?

doctortt
05-01-2011, 04:02 PM
Did you paste the code into the ThisWorkbook module?

I right clicked the worksheet and selected view codes. That brought me to the editior and I pasted the codes there.

Aussiebear
05-01-2011, 11:53 PM
Your code needs to reside in the ThisWorkbok module. Please check which module you have placed the code into.

doctortt
05-02-2011, 08:23 AM
Your code needs to reside in the ThisWorkbok module. Please check which module you have placed the code into.


Ohh!! I found 'ThisWorkbook' module, and it's working the way that I want now.

Thank you so much