 
View Full Version : Banale problema di Visual Basic - excel
ciao! premetto che non sono un programmatore...
ma kiedo a voi luminari!!!
chi è in grado di realizzare una macro in vbasic, che permetta di visualizzare un solo foglio excel a scelta sulla base di una var di input?
se avete idee per risolvere lo stesso problema con metodi + semplici tanto meglio   :)  
please help
Puoi creare una macro simile a questa, da inserire nell'evento Activate dell'oggeto wordbook (Exel obj: ThisWordbook)
Private Sub Workbook_Activate()
    Dim oSheet          As Worksheet
    Dim lCounter        As Long
    Dim sMsg            As String
    Dim sValue          As String
    Dim lNumSheetSelect As Long
    Dim bOK             As Boolean
                    
    ' *** Se c'è solo un foglio non faccio nulla
    If Me.Worksheets.Count <= 1 Then Exit Sub
    
    ' *** Scorro tutti i fogli e genero un messaggio da visualizzare all'utente
    For Each oSheet In Me.Worksheets
        lCounter = lCounter + 1
        sMsg = sMsg & lCounter & ") " & oSheet.Name & vbCrLf
    Next oSheet
           
    Do While Not bOK        ' *** Ciclo finchè l'utente non indica quale foglio usare...
           
        sValue = InputBox(sMsg, "Inserisci il nr° del foglio che vuoi attivare")
                       
        bOK = IsNumeric(sValue)
        
        If bOK Then
            lNumSheetSelect = Val(sValue)
        Else
            MsgBox "Devi inserire un numero!"
        End If
        If bOK Then
            If lNumSheetSelect < 1 Or lNumSheetSelect > lCounter Then
                bOK = False
                MsgBox "Devi inserire un numero (tra 1 e " & lCounter & ")"
            End If
        End If
                
    Loop
            
    ' *** Come prima cosa visualizzo il foglio selezionato dall'utente, perchè deve sempre
    '     esserci almeno un foglio visibile (altrimenti viene generato un errore)
    '
    Me.Worksheets(lNumSheetSelect).Visible = xlSheetVisible
    
    ' *** Nascondo tutti gli altri fogli
    '
    lCounter = 0
    For Each oSheet In Me.Worksheets
                
        lCounter = lCounter + 1
        If lCounter <> lNumSheetSelect Then
            oSheet.Visible = xlSheetHidden
        End If
    Next oSheet
               
End Sub
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.