Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2024, 05:36 PM
gmaxey gmaxey is offline Macro to produce a list of all the unique words in a doc Windows 10 Macro to produce a list of all the unique words in a doc Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 03-03-2024, 06:34 PM
ladracer ladracer is offline Macro to produce a list of all the unique words in a doc Windows 10 Macro to produce a list of all the unique words in a doc Office 2010
Novice
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default You likely getting tired of me....I don't blame you.

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?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to produce a list of all the unique words in a doc Macro to Find & Highlight Words from List DRD992 Word VBA 15 06-17-2023 05:06 AM
Macro to produce a list of all the unique words in a doc Sorting does not produce an alphabetical list. alanterrill Word 7 11-22-2022 12:31 PM
Macro to produce a list of all the unique words in a doc Macro to highlight a list of words bakerkr Word VBA 4 10-19-2017 02:23 PM
Macro to produce a list of all the unique words in a doc 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:34 AM.


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