+ Reply to Thread
Results 1 to 2 of 2

How to make Workbooks.Open skip password protected files

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2010
    Posts
    72

    Wink How to make Workbooks.Open skip password protected files

    I have the following code, which does what it should but I wanted to add a clause to the last line to ignore all files that are password protected. There are a few hundred files, and pressing cancel on each one is tedious. It is not an option to use the password as an argument, so I am just trying to skip the protected workbooks.

        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
            .EnableEvents = False
    
            On Error Resume Next
    
            Set wbThis = ThisWorkbook
                spname = "ERROR"
                 spid2 = "ERROR"
                aCount = 0
            
            With .FileSearch
                .NewSearch
                'Change path to suit
                .LookIn = "C:\CP"
                .FileType = msoFileTypeExcelWorkbooks
    
                If .Execute > 0 Then    'Workbooks in folder
                    For lCount = 1 To .FoundFiles.Count    'Loop through all.
                        'Open Workbook x and Set a Workbook variable to it
                        
                        PlzWait.Show False
                        PlzWait.Label1.Caption = lCount
                        PlzWait.Label2.Caption = .FoundFiles.Count
                        DoEvents
                        
                        Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), ReadOnly:=True, UpdateLinks:=0)
    Last edited by hoffey; 09-24-2009 at 11:01 AM.

  2. #2
    Registered User
    Join Date
    06-30-2009
    Location
    Southern California, Earth
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: How to make Workbooks.Open skip password protected files

    I added a blank password and added an "On Error GoTo" to skip over the file open. Works like a charm.

    Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), ReadOnly:=True, UpdateLinks:=0, Password:="")

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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