Results 1 to 3 of 3
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Skip File which is Open-Password Protected (97+)

    Using

    Set oWB = Workbooks.Open(strFileName)

    in a loop to process a group of files, the password dialog pops if the file has been set to require a password to open. Since the file isn't yet open, I can't get

    boolOpenProtected = oWB.HasPassword

    ... or can I? Is there any way to to set the process to say OK, forget this file and move to the next file?
    -John ... I float in liquid gardens
    UTC -7ąDS

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Skip File which is Open-Password Protected (97+)

    The following seems to work in XL2K:

    <pre>Public Sub Test()
    Dim oWB As Workbook
    Dim strFileName As String
    strFileName = "C:WorkPWFile.xls"
    Application.DisplayAlerts = False
    Set oWB = Nothing
    On Error Resume Next
    Set oWB = Workbooks.Open(Filename:=strFileName, Password:="asdfgh")
    On Error GoTo 0
    If oWB Is Nothing Then
    MsgBox "Could not open " & strFileName
    End If
    Application.DisplayAlerts = True
    End Sub
    </pre>

    Legare Coleman

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Skip File which is Open-Password Protected (97+)

    Thank, you, thank you. I didn't think to feed it a bogus password to see what happens, I thought that would prevent opening unprotected WBs.

    And if the password happens to be "asdfgh", that'll be a bonus. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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