Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Password to Open File (XP)

    What would be the code to recognize that a file requires a password to open it? I have a number of workbooks that I open via code, some of which are password protected to open. For these password protected files, I would like to move them to another folder. I already have the code to move the files.

    using: Workbooks.Open Filename:= ("XXXX.xls")

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File Password to Open File (XP)

    You could use code like this:

    Dim wbk As Workbook
    On Error Resume Next
    Set wbk = Workbooks.Open(Filename:="zzzz.xls", Password:="")
    If Err Then
    ' Couldn't open workbook, presumably because it is protected
    ...
    End If

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Password to Open File (XP)

    Hans,

    It worked.

    Many thanks,
    John

Posting Permissions

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