Home > Scripting > Generate passwords into an Excel file

Generate passwords into an Excel file

There are alot of user accounts mutations when a new school year starts. Creating hunderds of new user accounts can be a hassle and all those new accounts also need an password. This little script will generate passwords and place them into an excel file. This excel file can be used to create all those accounts with the generated password.

‘enable debugging
Option Explicit

‘create memory for objects
Dim objExcelRange, objExcelRange1, objExcelRange2, objExcel, objExcelWorkbook, objExcelCell
Dim objPasswordLoops, objRandomCharacter, objPasswordMFactor, objPasswordNumber, objPasswordChar, objPasswordNext

‘define globale constants
Const strExcelFileName = “D:\student.xls”
Const strExcelBoxTitle = “Password Generator for an Excelfile”
Const strPasswordLength = 6
Const  strPasswordCharacters = “abc1de2fg3hi4jk5lm6no7pqrs9tuvw0xyz”

‘asking for values
objExcelRange1=InputBox(“Enter value for the first cell” & VBCRLF & “(Example: G2) :”,strExcelBoxTitle,”G2″)
objExcelRange2=InputBox(“Enter value for the last cell” & VBCRLF & “(Example: G100) :”,strExcelBoxTitle,”G100″)
objExcelRange = objExcelRange1 & “:” & objExcelRange2

‘create an excel instance and open workbook
Set objExcel = CreateObject(“Excel.Application”)
Set objExcelWorkbook = objExcel.Workbooks.Open(strExcelFileName)

‘generate password for every cell entered into inputbox
For Each objExcelCell In objExcel.Range(objExcelRange)
 objExcelCell.Value = StrPassword(strPasswordLength,strPasswordCharacters)

‘close and save excelfile
objExcelWorkbook.SaveAs strExcelFileName

‘***********************      Functions       ****************************
Function GenIt(objPasswordMFactor)
end Function
Function StrPassword(strPasswordLength,strPasswordCharacters)

StrPassword = “”

objPasswordMFactor = Len(strPasswordCharacters)

For objPasswordNumber=1 to strPasswordLength
 objPasswordChar = GenIt(objPasswordMFactor)
 objPasswordNext = Mid(strPasswordCharacters,objPasswordChar,1)
 StrPassword = StrPassword & objPasswordNext
End Function

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: