+ Reply to Thread
Results 1 to 3 of 3

Password removal via VBA (as defined in the code with password)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Password removal via VBA (as defined in the code with password)

    Afternoon happy campers,

    First off - This is not a request to bypass or break a password, i have the password and want to know how to modify my current code.

    I have the following code in one of my sheets:

    Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim myPassword As String
        Dim wSheet As Worksheet
    myPassword = "pass123"
        If Environ("USERNAME") = "joe.bloggs" Then
            For Each wSheet In ActiveWorkbook.Worksheets
             wSheet.Unprotect Password:=myPassword
            Next
            End If
        If Environ("USERNAME") = "bob.hope" Then
            For Each wSheet In ActiveWorkbook.Worksheets
             wSheet.Unprotect Password:=myPassword
            Next
        If Environ("USERNAME") = "no.hope" Then
            For Each wSheet In ActiveWorkbook.Worksheets
             wSheet.Unprotect Password:=myPassword
            Next
    Application.ScreenUpdating = True
    End Sub
    Which works fine, however, i want to add code to it that will look at the username, and if for example the user is 'Tom.Jones' then the code would only unlokc 'Sheet.3' and nnot the whole file.

    Your help, as always is greatly appreciated.

  2. #2
    Forum Contributor
    Join Date
    03-14-2012
    Location
    location
    MS-Off Ver
    Excel 2007
    Posts
    170

    Re: Password removal via VBA (as defined in the code with password)

    perhaps something like this
    Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim myPassword As String
        Dim wSheet As Worksheet
    myPassword = "pass123"
        If Environ("USERNAME") = "joe.bloggs" Then
            For Each wSheet In ActiveWorkbook.Worksheets
             wSheet.Unprotect Password:=myPassword
            Next
            End If
        If Environ("USERNAME") = "bob.hope" Then
            For Each wSheet In ActiveWorkbook.Worksheets
             wSheet.Unprotect Password:=myPassword
            Next
            End If
        If Environ("USERNAME") = "Tom.Jones" Then
            For Each wSheet In ActiveWorkbook.Worksheets
             wSheet.Protect Password:=myPassword
            Next
            Sheet3.Unprotect Password:=myPassword
            End If
    Application.ScreenUpdating = True
    End Sub
    blue

  3. #3
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    879

    Re: Password removal via VBA (as defined in the code with password)

    Hi Blue,
    Thans for the code, i will check shortly and feedback :D

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can't pass password through code, keeps prompting for password
    By Alexander40 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2012, 03:55 PM
  2. password removal
    By jgomez in forum Excel General
    Replies: 1
    Last Post: 01-06-2011, 05:25 PM
  3. Replies: 0
    Last Post: 04-26-2006, 10:25 PM
  4. Password removal
    By leenanall in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2005, 03:06 PM
  5. VBA Password Removal??
    By Buffyslay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2005, 10:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1