Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-28-2017, 10:45 PM
branko branko is offline Help to include header and footer in string search code which i already have. Windows 7 64bit Help to include header and footer in string search code which i already have. Office 2010 64bit
Novice
Help to include header and footer in string search code which i already have.
 
Join Date: Mar 2017
Posts: 1
branko is on a distinguished road
Default Help to include header and footer in string search code which i already have.

Hi All, I am new to the whole VBA scene and even newer to the forum scene. Please let me know if i am doing anything the wrong way.
I have come across the following code and managed to make some amendments to get it working.
In my testing i have noticed that the searching is omitting the headers and footers and i am not savvy enough to get it working (i think i am in over my head!).
I have over 6000 documents to search through and create a database of where one of 100 words or phrases is listed.
The script gives me exactly what i need however i just need to get it to include the header and footer of each document.
I am running Windows 7 with Office 2010.
If anyone could help me modify the code to include the headers and footers i would be very grateful!
The code i am currently using is below. Let me know if any further info is required..
Many thanks!
Branko.


Sub Main()

Const TARGET_FOLDER_PATH As String = "C:\TEMP\"

Dim fso As FileSystemObject
Dim oTargetFolder As Folder
Dim f As File

Dim appWD As Word.Application
Dim docSource As Word.Document
Dim oSearchRange As Word.Range

Dim rngPartnumber As Range
Dim Rw As Long, Paras As Long, Chk As Long


Set fso = New FileSystemObject
Set oTargetFolder = fso.GetFolder(TARGET_FOLDER_PATH)

Set appWD = New Word.Application
For Each rngPartnumber In Range("partnumbers")
Rw = rngPartnumber.Row
For Each f In oTargetFolder.Files
If UCase(Right(f.Name, 4)) = "DOCX" Then
Set docSource = appWD.Documents.Open(TARGET_FOLDER_PATH & f.Name)
Set oSearchRange = docSource.Content
With oSearchRange.Find
.ClearFormatting
.MatchWholeWord = True
.Text = rngPartnumber.Text
Do
If .Execute Then


docSource.Range(docSource.Paragraphs(1).Range.Star t, _
oSearchRange.End).Select
Paras = appWD.ActiveWindow.Selection.Paragraphs.Count
Cells(Rw, 256).End(xlToLeft).Offset(0, 1).Value = f.Name & " *Page: " & _
appWD.ActiveWindow.Selection.Information(wdActiveE ndPageNumber) _
& " *Para: " & Paras
End If
If Paras = Chk Then Exit Do
Chk = Paras
Loop
End With
docSource.Close False
End If
Next f
Next rngPartnumber
appWD.Quit False
End Sub
Reply With Quote
 

Tags
search string



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to include header and footer in string search code which i already have. Include header and footer formatting when using IF conditional includes of separate documents anakaine Mail Merge 3 11-06-2015 09:51 PM
Header and footer aligned in the footer area ashiqghfr Word 2 07-23-2015 01:14 AM
Windows Search Does Not Include Outlook jkingston Outlook 0 07-20-2014 08:43 AM
Help to include header and footer in string search code which i already have. Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
include heading text in header eNGiNe Word 2 03-06-2013 12:24 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:40 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft