View Full Version : HELP VBA code
misghost
11-11-2015, 11:11 PM
guys if sameone know, and its can possoble, if i run VBA code need before run ask me to password enter, is any like VBA code??, thx
mancubus
11-12-2015, 08:31 AM
try this.
dont forget to password protect your vba Project and keep in mind that this also can be hacked by third party tools..
Sub vbax_54262_Password_Run_Macro()
Dim vPass As Variant
Dim sPass As String
sPass = "RealPassword"
vPass = Application.InputBox(Prompt:="Please enter password to proceed...", Title:="Password", Default:="Password")
If vPass = False Then 'Cancel button pressed
MsgBox "You pressed cancel. Quitting macro....", vbOKOnly, "Cancelled"
Exit Sub
End If
If vPass <> sPass Then 'Wrong password entered
MsgBox "Please enter correct password. Quitting macro....", vbOKOnly, "Wrong password"
Exit Sub
End If
'all code here when password is correct
'
'
'
End Sub
misghost
11-12-2015, 10:56 PM
big thx i will try,
misghost
11-12-2015, 11:03 PM
wow so cool code its works and its is what i needed thxxx
misghost
11-12-2015, 11:18 PM
i use this code but can u anderstand me one step, how recognize vPass to sPass? i mean when i tipe my sPass="pasword" i get permision to enter in my VBA code means its starting work " when my code is corect", how it heppens, i need realise for my self this code that why i ask, thx
mancubus
11-13-2015, 01:56 AM
inputbox asks user to type the password in the box.
if cancel button is pressed, the condition within If EndIf block is satisfied and Exit Sub statement terminates the macro.
if wrong password is entered, other condition within If EndIf block is met and Exit Sub statement terminates the macro.
if the correct password is entered, it maenas above conditions are not met, Exit Sub statements kinda gnored and code execution skips to next line.
you dont have to assign your password to a variable. you can also rewrite the code as below:
Sub vbax_54262_Password_Run_Macro()
Dim vPass As Variant
vPass = Application.InputBox(Prompt:="Please enter password to proceed...", Title:="Password", Default:="Password")
If vPass = False Then 'Cancel button pressed
MsgBox "You pressed cancel. Quitting macro....", vbOKOnly, "Cancelled"
Exit Sub
End If
If vPass <> "RealPassword" Then 'Wrong password entered
MsgBox "Please enter correct password. Quitting macro....", vbOKOnly, "Wrong password"
Exit Sub
End If
'all code here when password is correct
'
'
'
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.