Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    21

    Unanswered: Displaying userform uponing opening excel sheet

    Hi there

    I need help to display a userform when I open a particular excel sheet.(Meaning when I open the excel sheet, the userform will automatically appear with it).I can't seem to use the userform1.show command. Is there any vb code to do this coz I am using vb to write the code? pls help.thanks

    david

  2. #2
    Join Date
    Dec 2003
    Location
    San Diego, CA
    Posts
    153
    Welcome to the Board!

    Have you looked into a Workbook_Open event?

    I.E.
    Code:
    Private Sub Workbook_Open
      UserForm1.Show
    End Sub
    That's for if you if you open a workbook, and it goes in the This Workbook module. For a sheet event, just change it to Private Sub Worksheet_Activate and put it in that sheet's module.

    Hope that helps,

    Smitty

  3. #3
    Join Date
    Feb 2004
    Posts
    21

    Thanks

    Thanks Smitty.It would perfectly.

    Can I ask u another question. For the open method, I have to include the code in that workbook. If I want to use

    Private Sub Workbook_Open()

    UserForm1.Show

    End Sub

    but if the workbook's name is another like "company". Can I change the "workbook" to "company"? And where do I put the code?

    Thanks

    David

  4. #4
    Join Date
    Dec 2003
    Location
    San Diego, CA
    Posts
    153
    but if the workbook's name is another like "company". Can I change the "workbook" to "company"? And where do I put the code?
    If I think I get what you're asking regarding the ThisWorkbook module. That is a static name and will be the same regardless of the workbook's actual name.

    Workbook level events go into that module. I.E. Workbook_Open, Workbook_BeforeClose, Workbook_BeforePrint, etc. Event names are always the same (partially to keep you sane), so SmittysNewWorkbook_Open wouldn't do a damn thing, but Workbook_Open within Smitty's New Workbook would.

    Worksheet level events go in the specific sheet modules, Worksheet_Activate, Worksheet_Deactivate. Both are Private Subs. ActiveX Control code is also stored in these modules. I.E. if you place a Control Toolbox Command Button in a worksheet, its code goes in that sheet's module.

    General Subs, which can be called from anywhere in the workbook go in General Modules, which you place by going to Insert-->Module. Converse to ActiveX controls, Forms controls are assigned macros stored in General modules.

    Clear as mud now?

    Hope that helps,

    Smitty

Posting Permissions

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