Question : Can I browse Documents with VBA without opening them

Is it possible to browse for headings (like Heading1) in documents without opening them? I use Office 97 and VBA.

Answer : Can I browse Documents with VBA without opening them

Here is some code that will look through a folder and return the name of Documents containg the text "Good". I don't know your exact situation, but I'm sure you can tweak it a little.

Dim Fs As Object
Dim i As Integer
Dim strItems As String

Set Fs = Application.FileSearch
With Fs
    .NewSearch
    .LookIn = "C:\My Documents" 'Path
    .FileName = "*.Doc" 'Search through all word document
    .SearchSubFolders = True
    .TextOrProperty = "Good*" 'Find Word doc(s) contatining this text

        If .Execute > 0 Then
            If MsgBox("There were " & .foundfiles.Count & " " & "Files found in the " & .LookIn & " Folder" & vbCrLf & _
            "Do you want to continue?", vbYesNo + vbQuestion, "Found Files") = vbYes Then
                    For i = 1 To .foundfiles.Count 'enumerate through found files
                     strItems = .foundfiles(i) 'put file name in Variable
                     Debug.Print strItems
                     'do something to the files
                    Next
            End If
        Else:
            MsgBox "No Files Found"
        End If
End With
Random Solutions  
 
programming4us programming4us