View Single Post
 
Old 03-03-2024, 04:11 PM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote