+ Reply to Thread
Results 1 to 3 of 3

Unprotecting multiple files in folder in a sub

  1. #1
    Registered User
    Join Date
    08-14-2018
    Location
    San Francisco
    MS-Off Ver
    365 Business
    Posts
    6

    Unprotecting multiple files in folder in a sub

    Hello I need to unprotect (no password) about 200 files in a folder before I can run the script below (which allows me to Find and Replace in all those files)
    Any idea on how I can incorporate "unprotect" each file in my script??? Or even a separate script is fine. The only things I can find are for password protected files and its not working for me.

    Capture.JPG

    Thanks!

    ##########################
    Sub ReplaceInFolder()
    Dim strPath As String
    Dim strFile As String
    Dim wbk As Workbook
    Dim wsh As Worksheet
    Dim strFind As String
    Dim strReplace As String
    strFind = InputBox("Enter Text to Find")

    If strFind = "" Then
    MsgBox "No find text specified!", vbExclamation
    Exit Sub
    End If
    strReplace = InputBox("Enter Text to Replace")

    With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then
    strPath = .SelectedItems(1)
    Else
    MsgBox "No folder selected!", vbExclamation
    Exit Sub
    End If
    End With
    If Right(strPath, 1) <> "\" Then
    strPath = strPath & "\"
    End If
    Application.ScreenUpdating = False
    strFile = Dir(strPath & "*.xls*")
    Do While strFile <> ""
    Set wbk = Workbooks.Open(Filename:=strPath & strFile, AddToMRU:=False)
    For Each wsh In wbk.Worksheets
    wsh.Cells.Replace What:=strFind, Replacement:=strReplace, _
    LookAt:=xlWhole, MatchCase:=False
    Next wsh
    wbk.Close SaveChanges:=True
    strFile = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub

    ################################

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Unprotecting multiple files in folder in a sub

    Try something like

    Please Login or Register  to view this content.
    Martin

  3. #3
    Registered User
    Join Date
    08-14-2018
    Location
    San Francisco
    MS-Off Ver
    365 Business
    Posts
    6

    Re: Unprotecting multiple files in folder in a sub

    Worked like a charm! Thx!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 01-28-2019, 06:55 PM
  2. Macro for Creating one master data files from multiple files in the folder
    By NikhilDixit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2017, 03:10 PM
  3. Need help for consolidating cell values from multiple files in folder into master files
    By gurtejhira in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2017, 12:14 PM
  4. Replies: 0
    Last Post: 11-28-2013, 12:03 PM
  5. Replies: 1
    Last Post: 03-12-2013, 04:45 AM
  6. Replies: 1
    Last Post: 02-29-2012, 01:15 PM
  7. "Folder Select" Dialogue - Opening multiple files from selected folder
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2005, 10:05 AM

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