Solved

Solution for Simple Application.File search

Posted on 2014-02-05
2
200 Views
Last Modified: 2014-02-06
Found a new use for this old code utalizing application.filesearch. Trouble is this function is not available in MS Word 2007.   Quick 500 Points for a resolution.

Public Sub UnprotectBatch()

' Created 01/05/2004
' RESULT: Files found in the search are Unprotected
flocation = InputBox("Enter full path for the files to unprotect.", "Batch Unprotection")
If flocation = "" Then Exit Sub
Application.ScreenUpdating = False
Set fs = Application.FileSearch
    With fs
        .LookIn = flocation
        .SearchSubFolders = False
        .FileName = "*.doc"
        If .Execute() > 0 Then
            For i = 1 To .FoundFiles.Count
                Documents.Open fs.FoundFiles(i)
                On Error Resume Next
                ActiveDocument.Unprotect Password:="tbd"
                ActiveDocument.Save
                ActiveDocument.Close
            Next i
        Else
            MsgBox "There are no MS Word files found in the location specified."
        End If
    End With
End Sub
0
Comment
Question by:mcjann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39836541
Hi,

pls try

Sub macro3()
Set fso = CreateObject("Scripting.FileSystemObject")
flocation = InputBox("Enter full path for the files to unprotect.", "Batch Unprotection")
If flocation = "" Then Exit Sub
On Error Resume Next
Set ObjFolder = fso.GetFolder(flocation)
On Error GoTo 0
If IsEmpty(ObjFolder) Then
    MsgBox "Folder not valid"
    Exit Sub
End If
Set ObjFiles = ObjFolder.Files
For Each ObjFile In ObjFiles
    If ObjFile.Name Like "*.doc" Then
        Documents.Open (ObjFile.Name)
        On Error Resume Next
        ActiveDocument.Unprotect Password:="tbd"
        ActiveDocument.Save
        ActiveDocument.Close
    End If
Next
If IsEmpty(ObjFiles) Then MsgBox "There are no MS Word files found in the location specified."
End Sub

Open in new window

EDIT Filter *.doc Documents

Regards
0
 
LVL 1

Author Closing Comment

by:mcjann
ID: 39839552
I appreciate the solution and not just a link to follow.

500 Points awarded.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Viewers will learn the different options available in the Backstage view in Excel 2013.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question