I have a password in excel and I want to change it in vba

0
If Me.boxPassword.Value = "12345" Then

    Unload Me
    Sheets("Configuração").Visible = True
    Sheets("Configuração").Select

Else
    Me.Hide
    Retry = MsgBox("Passe incorreta, Tentar outra vez?", vbYesNo, "Retry?")

    Select Case Retry
        Case Is = vbYes
            Me.boxPassword.Value = ""
            Me.boxPassword.SetFocus
            Me.Show

        Case Is = vbNo
            Unload Me

    End Select
End If

This is functional, what I wanted now was to know how to have a method that would allow me to change the password to any other

    
asked by anonymous 22.10.2018 / 17:24

1 answer

0

From the search I made it looks like the only way to change the password of a worksheet is to save it with the Workbook.SaveAs() method:

' Usando o parâmetro 'Password' o arquivo só poderá ser aberto com a senha. 
Workbooks(1).SaveAs Password:="[nova_senha]"

' Usando o parâmetro 'WriteResPassword', se a senha não for informada o arquivo
' não será poderá ser editado, mas será aberto como somente leitura.
Workbooks(1).SaveAs WriteResPassword:="[nova_senha]"

Sources:

  

VBA Code to Password Protect an Excel file - Excel off the grid
Setting password on Excel files using VBA - Stack Overflow
Workbook.SaveAs Method (Excel) | Microsoft Docs

    
22.10.2018 / 17:51