Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-07-2017, 09:55 AM
DeductiveBear23 DeductiveBear23 is offline New to VBA Windows 10 New to VBA Office 2016
Novice
New to VBA
 
Join Date: Apr 2017
Posts: 4
DeductiveBear23 is on a distinguished road
Unhappy New to VBA

Hello All,



Very new to the entire world of VBA and Macros. I started with a want to add a random password generator to Word document. Some other people wanted the same thing and they were provided with some code that works exactly how I would like to it to.
This being said, I would like the randomized string of characters to appear in a table titled 'Password' instead of the message box. The code I am using is:
Code:
Sub PASSWORD_GENERATOR()
MsgBox Pwd(8)
End Sub
 
Function Pwd(iLength As Integer) As String
Dim i As Integer, iTemp As Integer, bOK As Boolean, strTemp As String
'48-57 = 0 To 9, 65-90 = A To Z, 97-122 = a To z
'amend For other characters If required
For i = 1 To iLength
  Do
    iTemp = Int((122 - 48 + 1) * Rnd + 48)
    Select Case iTemp
      Case 48 To 57, 65 To 90, 97 To 122: bOK = True
      Case Else: bOK = False
    End Select
  Loop Until bOK = True
  bOK = False
  strTemp = strTemp & Chr(iTemp)
Next i
Pwd = strTemp
End Function
I was able to produce the desired result in an Excel cell by changing the second last line where 'Pwd = strTemp' to ActiveSheet.Range("C2").Formula = pw (C2 being any cell I need it to be). I have tried "ActivTable.Range ("Password") Formula = pw" but I always get a 424 error and am not sure what or where to place the missing 'Object'.

As always - Any and all assistance is appreciated - Thank you

Last edited by macropod; 05-02-2017 at 03:56 PM. Reason: Added code tags & formatting
Reply With Quote
 

Tags
msg box, table, vba in microsoft word



Other Forums: Access Forums

All times are GMT -7. The time now is 02:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft