' ランダムな文字列生成
Public Function MakePassword(Optional intLength As Integer = 8, Optional boolIncUpper As Boolean = False, Optional boolIncSign As Boolean = False)
Dim strPass As String
Dim strLower As String
Dim strUpper As String
Dim strNumber As String
Dim strSign As String
Dim strChars As String
Dim intMax As Integer
Dim i As Integer
strLower = "qwertyuiopasdfghjklzxcvbnm"
strUpper = "QWERTYUIOPASDFGHJKLZXCVBNM"
strNumber = "123456789"
strSign = "-^@[;:],./!""#$%&'()=~|`{+*}<>?_"
strChars = strLower & strNumber & strUpper
If boolIncUpper = True Then
strChars = strChars & strUpper
End If
If boolIncSign = True Then
strChars = strChars & strSign
End If
intMax = Len(strChars)
For i = 1 To intLength
strPass = Mid(strChars, Int((intMax - 1 + 1) * Rnd + 1), 1) & strPass
Next i
MakePassword = strPass
End Function
Sub makePassworMain()
Dim selectionCell As Range
For Each selectionCell In Selection
selectionCell = MakePassword
Next
End Sub
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme