VBA Code to Generate a Random Password in Excel

VBA Code:

' VBA Code to Generate a Random Password in Excel
' This code generates a random password with specified length and character types

Sub GenerateRandomPassword()
    Dim passwordLength As Integer
    Dim password As String
    Dim characterPool As String
    Dim i As Integer
    
    ' Specify the desired password length
    passwordLength = 8
    
    ' Specify the character pool for the password
    characterPool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+"
    
    ' Initialize the password variable
    password = ""
    
    ' Generate the random password
    For i = 1 To passwordLength
        password = password & Mid(characterPool, WorksheetFunction.RandBetween(1, Len(characterPool)), 1)
    Next i
    
    ' Display the generated password in a message box
    MsgBox "The generated password is: " & password
End Sub


Check All VBA Codes

Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group
Nazim Khan - Author Image

Nazim Khan (Author) 📞 +91 9536250020
[MBA in Finance]

Nazim Khan is an expert in Microsoft Excel. He teaches people how to use it better. He has been doing this for more than ten years. He is running this website (TechGuruPlus.com) and a YouTube channel called "Business Excel" since 2016. He shares useful tips from his own experiences to help others improve their Excel skills and careers.

Leave a Comment