show userform in autoopen workbook

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

show userform in autoopen workbook

Post by sal21 »

I have this code:

Code: Select all

Private Sub Workbook_Open()

    Call AGGIORNA_ANA_SPORT
    Call RICOPIA_SEGMENTO_MERCATO
    Call RICOPIA_TGERARCHIA
    Call RICOPIA_CTR
    Call RICOPIA_AGENZIE

    ThisWorkbook.Sheets("AGENZIE").Range("A2:A200").ClearContents

End Sub
i need to apper a userform, before the code start, with 2 button but1 and but2.
If the user press but1 startm code in workbookopen if click but2 skipp all and simply open the workbook without to process the code..
Last edited by HansV on 28 Jan 2011, 21:54, edited 1 time in total.
Reason: to correct spelling in subject

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: show userform in autoopen workbook

Post by HansV »

Reduce the Workbook_Open code to

Code: Select all

Private Sub Workbook_Open()
  UserForm1.Show
End Sub
where UserForm1 is the name of the userform.

In the code behind the first command button, call the code you originally had in Workbook_Open, and close the form.

Code: Select all

Private Sub CommandButton1_Click()
    Call AGGIORNA_ANA_SPORT
    Call RICOPIA_SEGMENTO_MERCATO
    Call RICOPIA_TGERARCHIA
    Call RICOPIA_CTR
    Call RICOPIA_AGENZIE
    ThisWorkbook.Sheets("AGENZIE").Range("A2:A200").ClearContents
    Unload Me
End Sub
and in the code behind the second command button, just close the form:

Code: Select all

Private Sub CommandButton2_Click()
  Unload Me
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: show userform in autoopen workbook

Post by sal21 »

I'M stupid!
Sorry.
Tks for your patience.