Consulting

Results 1 to 6 of 6

Thread: HELP VBA code

  1. #1

    Post HELP VBA code

    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

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,645
    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
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    big thx i will try,

  4. #4
    wow so cool code its works and its is what i needed thxxx

  5. #5
    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

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,645
    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
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •