![]() |
|
|
|
#1
|
|||
|
|||
|
This should get you started. There are lots of examples out there on how to write code to loop through the files in a folder.
Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim strSrch() As String
Dim lngIndex As Long
Dim oRng As Range
Dim lngCount As Long
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
strSrch = Split("% if|% elif|% else|% endif|%p if|%p elif|%p else|%p endif", "|")
oTbl.Rows(2).Cells(1).Range.Text = ActiveDocument.FullName
For lngIndex = 0 To UBound(strSrch)
lngCount = 0
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = strSrch(lngIndex)
While .Execute
lngCount = lngCount + 1
oRng.Collapse wdCollapseEnd
Wend
oTbl.Rows(2).Cells(lngIndex + 2).Range.Text = lngCount
End With
Next
lbl_Exit:
Exit Sub
End Sub
|
|
#2
|
|||
|
|||
|
Mr. Maxey, Thank you for your help.
I just tried to run the macro and Word didn't like its name so once that was remedied, I tried it again, this time it errored and pointed to this line: oTbl.Rows(2).Cells(1).Range.Text = ActiveDocument.FullName The error stated: Run-time error '5941': The requested member of the collection does not exist. Any ideas what I may have done wrong? |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to Find & Highlight Words from List
|
DRD992 | Word VBA | 15 | 06-17-2023 05:06 AM |
Sorting does not produce an alphabetical list.
|
alanterrill | Word | 7 | 11-22-2022 12:31 PM |
Macro to highlight a list of words
|
bakerkr | Word VBA | 4 | 10-19-2017 02:23 PM |
Create list of unique words
|
trainingclc | Excel Programming | 3 | 09-29-2015 06:43 AM |
| Easiest Way to Produce a Report/List of Tagged Text from Multiple Word Files | bxchk | Word | 5 | 04-29-2014 03:23 PM |