Chiusura Userform dalla X



  • Chiusura Userform dalla X
    di beppexile data: 05/10/2016 12:09:26

    Salve ragazzi, mi sono accorto di avere un piccolo problema;
    per chiudere il mio file, visto che si lavora esclusivamente su userform, quando l'utente clicca sulla "X" della userform, chiudo il file ed anche excel con:

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    With Application
    .DisplayAlerts = False
    .ActiveWorkbook.Save
    .Quit
    ActiveWorkbook.Close False
    .DisplayAlerts = True
    End With
    End Sub

    Non mi ero reso conto che, se ho aperti altri file, mi chiude anche quelli.
    Dovrei sicuramente inserire un if per eseguire un controllo sui file aperti, del tipo:

    If "c'è aperto un solo il file di lavoro" Then
    "chiudi anche excel"
    Else
    "chiudi solo il file lavoro"
    End IF

    Tenendo conto che all'apertura del mio file, carico il suo nome in una variabile che chiamo FILE_LAVORO nel seguente modo:

    Private Sub Workbook_Open()
    FILE_LAVORO = ActiveWorkbook.Name
    'codice
    End Sub

    come faccio a farlo in maniera ottimale? Grazie a tutti.



  • di patel data: 05/10/2016 16:26:24

    potresti fare così
     
    With Application
    if workbooks.count = 1 then
      .DisplayAlerts = False
      ActiveWorkbook.Save
      .Quit 
    else
      ActiveWorkbook.Save
      ActiveWorkbook.Close False 
    end if
    end with
    






  • di beppexile data: 05/10/2016 16:48:31

    Si, mi sa che faccio proprio così.

    Grazie