Consulting

Results 1 to 7 of 7

Thread: Solved: Activate Macro When Sheet is Opened?

  1. #1

    Solved: Activate Macro When Sheet is Opened?

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Private Sub Workbook_Open()
    If OptionButton1.Value = True Then
    Showmethis 'this is the macro for launching something
    End if
    End Sub[/VBA]

    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    [vba]Private Sub Workbook_Open()
    If OptionButton1.Value = True Then
    Showmethis 'this is the macro for launching something
    End if
    End Sub[/vba]

    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?

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Did you paste the code into the ThisWorkbook module?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Quote Originally Posted by Aussiebear
    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.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Your code needs to reside in the ThisWorkbok module. Please check which module you have placed the code into.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Quote Originally Posted by Aussiebear
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •