+ Reply to Thread
Results 1 to 2 of 2

Avoid passwords when looping through workbooks

Hybrid View

kchm_2000 Avoid passwords when looping... 10-25-2011, 01:04 AM
kchm_2000 Re: Avoid passwords when... 10-28-2011, 04:46 AM
  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Avoid passwords when looping through workbooks

    Hi,

    I have some workbooks named password.xls which I loop through to do some clearing of contents for each sheet based on certain criteria. However, each time i run the loop, a pop up for password comes up. How do I avoid the passwords? In my password control sheet I have placed the desired password on cell A2 and file path on cell B2. Here are my codes for looping through workbooks. Thanks for any help in advance

    Sub RunCodeOnAllXLSFilesClear()
    Dim lCount As Long
    Dim wbResults As Workbook
    Dim wbCodeBook As Workbook
    
    
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    
    On Error Resume Next
        Set wbCodeBook = ThisWorkbook
            With Application.FileSearch
                .NewSearch
                'Change path to suit
                .LookIn = Cells(2, 2)
                .FileType = msoFileTypeAllFiles
                'Optional filter with wildcard
                '.Filename = "Book*.xls"
                    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
                            Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                            
                            'DO YOUR CODE HERE
                           
                           Call clearcontents
                           
                            wbResults.Close SaveChanges:=True
                            
                        Next lCount
                    End If
            End With
    On Error GoTo 0
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True
    End Sub
    and my code for each sheet

    Sub clearcontents()
    
    Dim S_heet As Worksheet
        For Each S_heet In ActiveWorkbook.Sheets
            If Left(S_heet.Name, 3) = "ACD" Then
                With S_heet
                    .Columns("F:G").clearcontents
                    .Columns("D:D").clearcontents
                End With
            End If
        Next S_heet
    End Sub
    Attached Files Attached Files
    Last edited by kchm_2000; 10-25-2011 at 01:13 AM.

  2. #2
    Registered User
    Join Date
    07-22-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Avoid passwords when looping through workbooks

    can someone help me with this?

+ 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