Consulting

Results 1 to 10 of 10

Thread: Dumb question - onLoad?

  1. #1

    Dumb question - onLoad?

    I know VB very well, but suck at VBA. I can't believe I have to ask this but I've searched for over an hour and found nothing.

    I have some labels, and such that I set to Visible= False. That works fine, through out the program they become visible based on what you click. But whenever I re-load the program they are Visible = True. Is there a way I can make them always Visible = False onLoad?

    Thanks in advance!

  2. #2
    VBAX Regular raj85's Avatar
    Joined
    Feb 2010
    Location
    Mumbai
    Posts
    34
    Location
    If you are using UserForm then on UserForm_Activate event you can write code that me.lable.visible = False such a way when your form will get loaded lable will be invisible.
    Same case if you are using excel sheet just need to use code in Worksheet_Activate event

  3. #3
    I put this code on my sheet1:

    'Onload
    Sub Worksheet_Activate()
    Label1.Visible = False
    ComboBox1.Visible = False
    Label2.Visible = False
    ComboBox2.Visible = False
    Range("B1") = "Month of:"
    End Sub
    It works, but it only works when I click the "run" button. I need it to work when the form is loaded form the user.
    Last edited by bobdole22; 08-27-2013 at 09:23 AM.
    "My common sense is tingling!" - Deadpool
    http://marveldcforum.com

  4. #4
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    If ActiveX control (Label, ComboBox and so on) is on the sheet or on UserForm then select it and do right click.
    Then choose Properties and set Visible to False.
    Save Workbook and that property will be saved too.

  5. #5
    Quote Originally Posted by ZVI View Post
    If ActiveX control (Label, ComboBox and so on) is on the sheet or on UserForm then select it and do right click.
    Then choose Properties and set Visible to False.
    Save Workbook and that property will be saved too.
    That works and is exactly what I've been doing. But afterward, I run the program which makes everything visible. Then when I re-open it, they are Visible = True again.
    "My common sense is tingling!" - Deadpool
    http://marveldcforum.com

  6. #6
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    Could you please clarify where the controls are - on UserForm or on Sheet?

    If controls are on a sheet then put this sub into ThisWorkbook module
    Private Sub Workbook_Open()
    ' Your code
      With Sheets("Sheet1")
        .Label1.Visible = False
        .ComboBox1.Visible = False
        .Label2.Visible = False
        .ComboBox2.Visible = False
        .Range("B1") = "Month of:"
      End With
    End Sub
    If controls are on a UserForm (Alt-F11 menu Insert - UserForm) then put this code into UserForm's module (Right Click - View Code):
     Private Sub UserForm_Initialize() ' The same as Form_Load() in VB
      ' Your code
      Label1.Visible = False
      ComboBox1.Visible = False
      Label2.Visible = False
      ComboBox2.Visible = False
      Sheets("Sheet1").Range("B1") = "Month of:"
    End Sub
    Last edited by ZVI; 08-27-2013 at 12:02 PM.

  7. #7
    Good idea, that is probably it! It's on sheet. I also tried putting it on Module1.
    "My common sense is tingling!" - Deadpool
    http://marveldcforum.com

  8. #8
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    Quote Originally Posted by bobdole22 View Post
    that is probably it!
    Not probably - it is exactly

    I also tried putting it on Module1.
    If you prefer using code in Module1 then Sub Auto_Open() is also triggered at open time even at Application.EnableEvents = False
    Sub Auto_Open() 
         ' Your code
        With Sheets("Sheet1") 
            .Label1.Visible = False 
            .ComboBox1.Visible = False 
            .Label2.Visible = False 
            .ComboBox2.Visible = False 
            .Range("B1") = "Month of:" 
        End With 
    End Sub

  9. #9
    Thanks! Perfect.
    "My common sense is tingling!" - Deadpool
    http://marveldcforum.com

  10. #10
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    Glad it helped!

Posting Permissions

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