Solved

Solution for Simple Application.File search

Posted on 2014-02-05
2
191 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
I appreciate the solution and not just a link to follow.

500 Points awarded.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Viewers will learn the different options available in the Backstage view in Excel 2013.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now