Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Solution for Simple Application.File search

Posted on 2014-02-05
2
Medium Priority
?
203 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
2 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

916 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