Results 1 to 5 of 5

Thread: [RESOLVED] Check for protected Excel files

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    Marlborough, MA
    Posts
    53

    Resolved [RESOLVED] Check for protected Excel files

    Hi, is there any way to check for protection status of a excel file before you open it. I am running a batch process on all excel files in a folder with out any user interaction, and if any of the file is password protested then I want to simply skip that file without opening it Because these files ask for the password as soon as I try to open them, thus requiring user interaction.

  2. #2
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049

    Re: Check for protected Excel files

    http://www.exceltip.com/st/Check_if_...Excel/500.html... Let the application open a workbook and let it check via the url source.. (I've decided to put the url up instead of the source)

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2005
    Location
    Marlborough, MA
    Posts
    53

    Re: Check for protected Excel files

    Hi Devion, you didn't understood my question. In your code you are checking whether the code module protection in the active document. But the document (or an excel file) becomes active document only after you opened it. If the file is password protected (where in it asks for the password as soon as you open the file) then it requires user interaction. Which I want to aviod. So basically I want to check the status of a file say xxx.xls with out firing application.open(xxx.xls).

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Check for protected Excel files

    Moved to Office Development.

  5. #5
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Check for protected Excel files

    Quote Originally Posted by mvadu
    Hi, is there any way to check for protection status of a excel file before you open it. I am running a batch process on all excel files in a folder with out any user interaction, and if any of the file is password protested then I want to simply skip that file without opening it :sick: Because these files ask for the password as soon as I try to open them, thus requiring user interaction. :eek2:
    Hi,

    Use the following code.
    VB Code:
    1. Sub OpenFile()
    2.     On Error GoTo ErrOpenFile
    3.     'Here the File1.xls is password protected; We are not providing
    4.     'the valid password here. So we will be getting an error.
    5.     'The error number will be 1004 in case of any issues when
    6.     'opening the file
    7.     Workbooks.Open Filename:="c:\temp\File1.xls", Password:=""
    8.     Workbooks.Open Filename:="c:\temp\File2.xls", Password:=""
    9.  
    10. ExitHere:
    11.     Exit Sub
    12.  
    13. ErrOpenFile:
    14.     If Err.Number = 1004 Then
    15.         'notify the user that "There is an issue when opening a file."
    16.         MsgBox "The file is password protected."
    17.         'To Continue with next file
    18.         Resume Next
    19.     End If
    20. End Sub
    Let me know if this code is not solved your issue.
    CS

Posting Permissions

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



Click Here to Expand Forum to Full Width