How to get Spreadsheet to hide and VBA form to load on application load

Posted on 2007-08-08
Last Modified: 2013-11-05
Hi Experts,

I need help with an Excel document that I am working on. What I need to do is upon the Excel document loading, hide Excel and display a VBA form. I am relatively new to VBA, so it could be something I am doing wrong or missing.

I have tried the following and similar methods in the actual sheet object, but to no avail...

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.Visible = False
End Sub

Any help would be greatly appreciated.
Question by:ringroselaw
    LVL 26

    Accepted Solution

    have you tried to do it in

    Private Sub Workbook_Open()

    Author Comment

    This works, but for some reason none of the data in the spreadsheet (sheet1) is shown within the corresponding text boxes on the form.

    Do I  need to apply a similar method to the sheet, as opposed to the Workbook?
    LVL 26

    Expert Comment

    if you want to set something to userform1


    Load UserForm1
    UserForm1.TextBox1.Text = Sheets("sheet1").Range("A1").Value

    Author Comment

    The form has been setup as above, so on the form loading the text boxes refer to the cells for their values.

    I think the problem lies with the way the data is merged into Excel.
    Because the data is merged in after the Workbook is opened, the form isn't displaying the data because this hasn't been inputted into cells yet (hope that makes sense).

    So what needs to happen is...
    - Document Opens
    - Data is merged into sheet cells
    - Application hides
    - Form shows

    LVL 46

    Assisted Solution

    by:Wayne Taylor (webtubbs)
    Hi ringroselaw,

    Try putting DoEvents after showing your form.



    Author Comment

    Thanks for your help guys.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now