Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Solution for Simple Application.File search

Posted on 2014-02-05
2
Medium Priority
?
201 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 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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 use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

715 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