![]() |
|
#1
|
|||
|
|||
![]()
In practice, the table will be in the main document (the one running the code).
e.g., Dim oDocMain as Document Dim oDocQuery as Document Set oDocMain = ActiveDocument Set oTbl = oDocMain.Tables(1) For Each oDocQuery In ... "Target folder of documents" Next oDocQuery |
#2
|
|||
|
|||
![]()
I created a document with a bevy of rows and 9 columns.
I attempted to run the code you provided with a slight modification and it states: Compile error: For Each may only iterate over a collection object or an array Sub JinjaSearch() 'A basic Word Macro coded by Gregory K. Maxey Dim strSrch() As String Dim strFolder As String Dim strFile As String Dim lngIndex As Long Dim oRng As Range Dim lngCount As Long Dim oDocMain As Document Dim oDocQuery As Document Set oDocMain = ActiveDocument Set oTbl = oDocMain.Tables(1) 'Dim oTbl As Table ' Pop up input boxes for user to enter folder path, the finding and replacing texts. strFolder = InputBox("Enter the folder path to the documents you want to change here:") 'For Each oDocQuery In strFolder For Each oDocQuery In strFolder 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 Next oDocQuery lbl_Exit: Exit Sub End Sub Where did I go wrong this time? |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
DRD992 | Word VBA | 15 | 06-17-2023 05:06 AM |
![]() |
alanterrill | Word | 7 | 11-22-2022 12:31 PM |
![]() |
bakerkr | Word VBA | 4 | 10-19-2017 02:23 PM |
![]() |
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 |