+ Reply to Thread
Results 1 to 7 of 7

access workbook protection password in VBA

  1. #1
    Registered User
    Join Date
    08-24-2005
    Location
    Philippines
    Posts
    75

    Question access workbook protection password in VBA

    Hi! Is it possible to access in VBA a "readable" version of the workbook protection password? I tried using the Password property of the Workbook object but it just returns a string of asterisks.

    I have an excel workbook (w/ VBA code). The workbook is password protected so users don't accidentally delete sheets, change sheet names, insert new sheets, etc... I allow the users to do these through a dynamically created menu. So, their actions are controlled.

    In order to do the changes, I use the ff code:

    MyWorkbook.Unprotect ThePassword
    'changes here... delete sheet, rename, insert, etc...
    MyWorkbook.Protect ThePassword, True

    I would like the user (admin for the particular excel file) to be able to specify the password...

  2. #2
    Dave Peterson
    Guest

    Re: access workbook protection password in VBA

    You could use inputbox to ask for the password and if it matches the password
    (you should know it), then continue.

    "T-容x" wrote:
    >
    > Hi! Is it possible to access in VBA a "readable" version of the workbook
    > protection password? I tried using the Password property of the Workbook
    > object but it just returns a string of asterisks.
    >
    > I have an excel workbook (w/ VBA code). The workbook is password
    > protected so users don't accidentally delete sheets, change sheet
    > names, insert new sheets, etc... I allow the users to do these through
    > a dynamically created menu. So, their actions are controlled.
    >
    > In order to do the changes, I use the ff code:
    >
    > MyWorkbook.Unprotect ThePassword
    > 'changes here... delete sheet, rename, insert, etc...
    > MyWorkbook.Protect ThePassword, True
    >
    > I would like the user (admin for the particular excel file) to be able
    > to specify the password...
    >
    > --
    > T-容x
    > ------------------------------------------------------------------------
    > T-容x's Profile: http://www.excelforum.com/member.php...o&userid=26572
    > View this thread: http://www.excelforum.com/showthread...hreadid=398493


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    08-24-2005
    Location
    Philippines
    Posts
    75

    Unhappy Query workbook password protection...

    well, yeah... initially, i do know the password (i set it). unfortunately, my workbook also has a 'Protect/Unprotect Workbook' menu item so that users can unprotect/protect the workbook w/out having to know and specify the password. (i did this in case users really need to make changes not accessible through the custom menu i provided.) Problem is, while the book is unprotected, users might protect it again using the buit-in 'Protect Workbook...' in the 'Tools|Protection' menu and specify a different password. If this happens, my code will crash because, then, the new password will not equal the hard-coded password. I'd like that, if possible, i'd not have to hard-code a password and just query the workbook for it.

    MyWorkbook.Unprotect QueriedPassword
    'changes here... delete sheet, rename, insert, etc...
    MyWorkbook.Protect QueriedPassword, True

    Thanks anywayz... i'll probably just have to find a different approach...
    Thanks!!!


    Quote Originally Posted by Dave Peterson
    You could use inputbox to ask for the password and if it matches the password
    (you should know it), then continue.

    "T-容x" wrote:
    >
    > Hi! Is it possible to access in VBA a "readable" version of the workbook
    > protection password? I tried using the Password property of the Workbook
    > object but it just returns a string of asterisks.
    >
    > I have an excel workbook (w/ VBA code). The workbook is password
    > protected so users don't accidentally delete sheets, change sheet
    > names, insert new sheets, etc... I allow the users to do these through
    > a dynamically created menu. So, their actions are controlled.
    >
    > In order to do the changes, I use the ff code:
    >
    > MyWorkbook.Unprotect ThePassword
    > 'changes here... delete sheet, rename, insert, etc...
    > MyWorkbook.Protect ThePassword, True
    >
    > I would like the user (admin for the particular excel file) to be able
    > to specify the password...
    >
    > --
    > T-容x
    > ------------------------------------------------------------------------
    > T-容x's Profile: http://www.excelforum.com/member.php...o&userid=26572
    > View this thread: http://www.excelforum.com/showthread...hreadid=398493


    --

    Dave Peterson

  4. #4
    Dave Peterson
    Guest

    Re: access workbook protection password in VBA

    Maybe you can just show that dialog and react afterwards:

    Option Explicit
    Sub testme()

    Dim wkbk As Workbook
    Set wkbk = ActiveWorkbook

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    On Error Resume Next
    Application.Dialogs(xlDialogWorkbookProtect).Show
    On Error GoTo 0

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    MsgBox "still protected"
    End If
    End If

    End Sub



    "T-容x" wrote:
    >
    > well, yeah... initially, i do know the password (i set it).
    > unfortunately, my workbook also has a 'Protect/Unprotect Workbook' menu
    > item so that users can unprotect/protect the workbook w/out having to
    > know and specify the password. (i did this in case users really need to
    > make changes not accessible through the custom menu i provided.) Problem
    > is, while the book is unprotected, users might protect it again using
    > the buit-in 'Protect Workbook...' in the 'Tools|Protection' menu and
    > specify a different password. If this happens, my code will crash
    > because, then, the new password will not equal the hard-coded password.
    > I'd like that, if possible, i'd not have to hard-code a password and
    > just query the workbook for it.
    >
    > MyWorkbook.Unprotect QueriedPassword
    > 'changes here... delete sheet, rename, insert, etc...
    > MyWorkbook.Protect QueriedPassword, True
    >
    > Thanks anywayz... i'll probably just have to find a different
    > approach...
    > Thanks!!!
    >
    > Dave Peterson Wrote:
    > > You could use inputbox to ask for the password and if it matches the
    > > password
    > > (you should know it), then continue.
    > >
    > > "T-容x" wrote:
    > > >
    > > > Hi! Is it possible to access in VBA a "readable" version of the

    > > workbook
    > > > protection password? I tried using the Password property of the

    > > Workbook
    > > > object but it just returns a string of asterisks.
    > > >
    > > > I have an excel workbook (w/ VBA code). The workbook is password
    > > > protected so users don't accidentally delete sheets, change sheet
    > > > names, insert new sheets, etc... I allow the users to do these

    > > through
    > > > a dynamically created menu. So, their actions are controlled.
    > > >
    > > > In order to do the changes, I use the ff code:
    > > >
    > > > MyWorkbook.Unprotect ThePassword
    > > > 'changes here... delete sheet, rename, insert, etc...
    > > > MyWorkbook.Protect ThePassword, True
    > > >
    > > > I would like the user (admin for the particular excel file) to be

    > > able
    > > > to specify the password...
    > > >
    > > > --
    > > > T-容x
    > > >

    > > ------------------------------------------------------------------------
    > > > T-容x's Profile:

    > > http://www.excelforum.com/member.php...o&userid=26572
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=398493
    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    > T-容x
    > ------------------------------------------------------------------------
    > T-容x's Profile: http://www.excelforum.com/member.php...o&userid=26572
    > View this thread: http://www.excelforum.com/showthread...hreadid=398493


    --

    Dave Peterson

  5. #5
    Registered User
    Join Date
    08-24-2005
    Location
    Philippines
    Posts
    75

    Smile

    not really what i'm looking for but you gave me an idea....
    one more thing... is there a way to manipulate the Workbook protect dialog?
    i haven't used Application.Dialogs before....

    Thanks a lot!!!

    Quote Originally Posted by Dave Peterson
    Maybe you can just show that dialog and react afterwards:

    Option Explicit
    Sub testme()

    Dim wkbk As Workbook
    Set wkbk = ActiveWorkbook

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    On Error Resume Next
    Application.Dialogs(xlDialogWorkbookProtect).Show
    On Error GoTo 0

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    MsgBox "still protected"
    End If
    End If

    End Sub



    "T-容x" wrote:
    >
    > well, yeah... initially, i do know the password (i set it).
    > unfortunately, my workbook also has a 'Protect/Unprotect Workbook' menu
    > item so that users can unprotect/protect the workbook w/out having to
    > know and specify the password. (i did this in case users really need to
    > make changes not accessible through the custom menu i provided.) Problem
    > is, while the book is unprotected, users might protect it again using
    > the buit-in 'Protect Workbook...' in the 'Tools|Protection' menu and
    > specify a different password. If this happens, my code will crash
    > because, then, the new password will not equal the hard-coded password.
    > I'd like that, if possible, i'd not have to hard-code a password and
    > just query the workbook for it.
    >
    > MyWorkbook.Unprotect QueriedPassword
    > 'changes here... delete sheet, rename, insert, etc...
    > MyWorkbook.Protect QueriedPassword, True
    >
    > Thanks anywayz... i'll probably just have to find a different
    > approach...
    > Thanks!!!
    >
    > Dave Peterson Wrote:
    > > You could use inputbox to ask for the password and if it matches the
    > > password
    > > (you should know it), then continue.
    > >
    > > "T-容x" wrote:
    > > >
    > > > Hi! Is it possible to access in VBA a "readable" version of the

    > > workbook
    > > > protection password? I tried using the Password property of the

    > > Workbook
    > > > object but it just returns a string of asterisks.
    > > >
    > > > I have an excel workbook (w/ VBA code). The workbook is password
    > > > protected so users don't accidentally delete sheets, change sheet
    > > > names, insert new sheets, etc... I allow the users to do these

    > > through
    > > > a dynamically created menu. So, their actions are controlled.
    > > >
    > > > In order to do the changes, I use the ff code:
    > > >
    > > > MyWorkbook.Unprotect ThePassword
    > > > 'changes here... delete sheet, rename, insert, etc...
    > > > MyWorkbook.Protect ThePassword, True
    > > >
    > > > I would like the user (admin for the particular excel file) to be

    > > able
    > > > to specify the password...
    > > >
    > > > --
    > > > T-容x
    > > >

    > > ------------------------------------------------------------------------
    > > > T-容x's Profile:

    > > http://www.excelforum.com/member.php...o&userid=26572
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=398493
    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    > T-容x
    > ------------------------------------------------------------------------
    > T-容x's Profile: http://www.excelforum.com/member.php...o&userid=26572
    > View this thread: http://www.excelforum.com/showthread...hreadid=398493


    --

    Dave Peterson

  6. #6
    Dave Peterson
    Guest

    Re: access workbook protection password in VBA

    If manipulate means populate some of those fields when you're protecting the
    sheet:

    Option Explicit
    Sub testme2()

    Dim wkbk As Workbook
    Set wkbk = ActiveWorkbook

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    'do nothing
    Else
    On Error Resume Next
    Application.Dialogs(xlDialogWorkbookProtect).Show True, False, "aa"
    On Error GoTo 0

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    'do nothing
    Else
    MsgBox "still unprotected"
    End If
    End If

    End Sub

    The parms for xlDialogWorkbookProtect are in this order:
    structure, windows, password

    If you click on dialogs and hit f1, you can use that to see all the dialogs and
    all their parms. (after a few clicks.)



    "T-容x" wrote:
    >
    > not really what i'm looking for but you gave me an idea....
    > one more thing... is there a way to manipulate the Workbook protect
    > dialog?
    > i haven't used Application.Dialogs before....
    >
    > Thanks a lot!!!
    >
    > Dave Peterson Wrote:
    > > Maybe you can just show that dialog and react afterwards:
    > >
    > > Option Explicit
    > > Sub testme()
    > >
    > > Dim wkbk As Workbook
    > > Set wkbk = ActiveWorkbook
    > >
    > > If wkbk.ProtectWindows _
    > > Or wkbk.ProtectStructure Then
    > > On Error Resume Next
    > > Application.Dialogs(xlDialogWorkbookProtect).Show
    > > On Error GoTo 0
    > >
    > > If wkbk.ProtectWindows _
    > > Or wkbk.ProtectStructure Then
    > > MsgBox "still protected"
    > > End If
    > > End If
    > >
    > > End Sub
    > >
    > >
    > >
    > > "T-容x" wrote:
    > > >
    > > > well, yeah... initially, i do know the password (i set it).
    > > > unfortunately, my workbook also has a 'Protect/Unprotect Workbook'

    > > menu
    > > > item so that users can unprotect/protect the workbook w/out having

    > > to
    > > > know and specify the password. (i did this in case users really need

    > > to
    > > > make changes not accessible through the custom menu i provided.)

    > > Problem
    > > > is, while the book is unprotected, users might protect it again

    > > using
    > > > the buit-in 'Protect Workbook...' in the 'Tools|Protection' menu and
    > > > specify a different password. If this happens, my code will crash
    > > > because, then, the new password will not equal the hard-coded

    > > password.
    > > > I'd like that, if possible, i'd not have to hard-code a password and
    > > > just query the workbook for it.
    > > >
    > > > MyWorkbook.Unprotect QueriedPassword
    > > > 'changes here... delete sheet, rename, insert, etc...
    > > > MyWorkbook.Protect QueriedPassword, True
    > > >
    > > > Thanks anywayz... i'll probably just have to find a different
    > > > approach...
    > > > Thanks!!!
    > > >
    > > > Dave Peterson Wrote:
    > > > > You could use inputbox to ask for the password and if it matches

    > > the
    > > > > password
    > > > > (you should know it), then continue.
    > > > >
    > > > > "T-容x" wrote:
    > > > > >
    > > > > > Hi! Is it possible to access in VBA a "readable" version of the
    > > > > workbook
    > > > > > protection password? I tried using the Password property of the
    > > > > Workbook
    > > > > > object but it just returns a string of asterisks.
    > > > > >
    > > > > > I have an excel workbook (w/ VBA code). The workbook is password
    > > > > > protected so users don't accidentally delete sheets, change

    > > sheet
    > > > > > names, insert new sheets, etc... I allow the users to do these
    > > > > through
    > > > > > a dynamically created menu. So, their actions are controlled.
    > > > > >
    > > > > > In order to do the changes, I use the ff code:
    > > > > >
    > > > > > MyWorkbook.Unprotect ThePassword
    > > > > > 'changes here... delete sheet, rename, insert, etc...
    > > > > > MyWorkbook.Protect ThePassword, True
    > > > > >
    > > > > > I would like the user (admin for the particular excel file) to

    > > be
    > > > > able
    > > > > > to specify the password...
    > > > > >
    > > > > > --
    > > > > > T-容x
    > > > > >
    > > > >

    > > ------------------------------------------------------------------------
    > > > > > T-容x's Profile:
    > > > > http://www.excelforum.com/member.php...o&userid=26572
    > > > > > View this thread:
    > > > > http://www.excelforum.com/showthread...hreadid=398493
    > > > >
    > > > > --
    > > > >
    > > > > Dave Peterson
    > > >
    > > > --
    > > > T-容x
    > > >

    > > ------------------------------------------------------------------------
    > > > T-容x's Profile:

    > > http://www.excelforum.com/member.php...o&userid=26572
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=398493
    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    > T-容x
    > ------------------------------------------------------------------------
    > T-容x's Profile: http://www.excelforum.com/member.php...o&userid=26572
    > View this thread: http://www.excelforum.com/showthread...hreadid=398493


    --

    Dave Peterson

  7. #7
    Registered User
    Join Date
    08-24-2005
    Location
    Philippines
    Posts
    75

    Talking

    Thanks!!! will try the code you gave (maybe 2-3 days from now)... still am busy now with other work (delphi)... Thanks a lot!!!

    Quote Originally Posted by Dave Peterson
    If manipulate means populate some of those fields when you're protecting the
    sheet:

    Option Explicit
    Sub testme2()

    Dim wkbk As Workbook
    Set wkbk = ActiveWorkbook

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    'do nothing
    Else
    On Error Resume Next
    Application.Dialogs(xlDialogWorkbookProtect).Show True, False, "aa"
    On Error GoTo 0

    If wkbk.ProtectWindows _
    Or wkbk.ProtectStructure Then
    'do nothing
    Else
    MsgBox "still unprotected"
    End If
    End If

    End Sub

    The parms for xlDialogWorkbookProtect are in this order:
    structure, windows, password

    If you click on dialogs and hit f1, you can use that to see all the dialogs and
    all their parms. (after a few clicks.)



    "T-容x" wrote:
    >
    > not really what i'm looking for but you gave me an idea....
    > one more thing... is there a way to manipulate the Workbook protect
    > dialog?
    > i haven't used Application.Dialogs before....
    >
    > Thanks a lot!!!
    >
    > Dave Peterson Wrote:
    > > Maybe you can just show that dialog and react afterwards:
    > >
    > > Option Explicit
    > > Sub testme()
    > >
    > > Dim wkbk As Workbook
    > > Set wkbk = ActiveWorkbook
    > >
    > > If wkbk.ProtectWindows _
    > > Or wkbk.ProtectStructure Then
    > > On Error Resume Next
    > > Application.Dialogs(xlDialogWorkbookProtect).Show
    > > On Error GoTo 0
    > >
    > > If wkbk.ProtectWindows _
    > > Or wkbk.ProtectStructure Then
    > > MsgBox "still protected"
    > > End If
    > > End If
    > >
    > > End Sub
    > >
    > >
    > >
    > > "T-容x" wrote:
    > > >
    > > > well, yeah... initially, i do know the password (i set it).
    > > > unfortunately, my workbook also has a 'Protect/Unprotect Workbook'

    > > menu
    > > > item so that users can unprotect/protect the workbook w/out having

    > > to
    > > > know and specify the password. (i did this in case users really need

    > > to
    > > > make changes not accessible through the custom menu i provided.)

    > > Problem
    > > > is, while the book is unprotected, users might protect it again

    > > using
    > > > the buit-in 'Protect Workbook...' in the 'Tools|Protection' menu and
    > > > specify a different password. If this happens, my code will crash
    > > > because, then, the new password will not equal the hard-coded

    > > password.
    > > > I'd like that, if possible, i'd not have to hard-code a password and
    > > > just query the workbook for it.
    > > >
    > > > MyWorkbook.Unprotect QueriedPassword
    > > > 'changes here... delete sheet, rename, insert, etc...
    > > > MyWorkbook.Protect QueriedPassword, True
    > > >
    > > > Thanks anywayz... i'll probably just have to find a different
    > > > approach...
    > > > Thanks!!!
    > > >
    > > > Dave Peterson Wrote:
    > > > > You could use inputbox to ask for the password and if it matches

    > > the
    > > > > password
    > > > > (you should know it), then continue.
    > > > >
    > > > > "T-容x" wrote:
    > > > > >
    > > > > > Hi! Is it possible to access in VBA a "readable" version of the
    > > > > workbook
    > > > > > protection password? I tried using the Password property of the
    > > > > Workbook
    > > > > > object but it just returns a string of asterisks.
    > > > > >
    > > > > > I have an excel workbook (w/ VBA code). The workbook is password
    > > > > > protected so users don't accidentally delete sheets, change

    > > sheet
    > > > > > names, insert new sheets, etc... I allow the users to do these
    > > > > through
    > > > > > a dynamically created menu. So, their actions are controlled.
    > > > > >
    > > > > > In order to do the changes, I use the ff code:
    > > > > >
    > > > > > MyWorkbook.Unprotect ThePassword
    > > > > > 'changes here... delete sheet, rename, insert, etc...
    > > > > > MyWorkbook.Protect ThePassword, True
    > > > > >
    > > > > > I would like the user (admin for the particular excel file) to

    > > be
    > > > > able
    > > > > > to specify the password...
    > > > > >
    > > > > > --
    > > > > > T-容x
    > > > > >
    > > > >

    > > ------------------------------------------------------------------------
    > > > > > T-容x's Profile:
    > > > > http://www.excelforum.com/member.php...o&userid=26572
    > > > > > View this thread:
    > > > > http://www.excelforum.com/showthread...hreadid=398493
    > > > >
    > > > > --
    > > > >
    > > > > Dave Peterson
    > > >
    > > > --
    > > > T-容x
    > > >

    > > ------------------------------------------------------------------------
    > > > T-容x's Profile:

    > > http://www.excelforum.com/member.php...o&userid=26572
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=398493
    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    > T-容x
    > ------------------------------------------------------------------------
    > T-容x's Profile: http://www.excelforum.com/member.php...o&userid=26572
    > View this thread: http://www.excelforum.com/showthread...hreadid=398493


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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