Re: Macro for Mass Find and Replace
- From: "Ann Marie" <ann@xxxxxxxxxxxxx>
- Date: Fri, 1 Sep 2006 21:59:21 +1000
Yes, it is quite strange.
"Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx> wrote in message
news:eqlF2NUzGHA.1300@xxxxxxxxxxxxxxxxxxxxxxx
Ann Marie,
I get "VBA Find and Replace User Interface" in the "Custom Toolbar" group
of the Addin Ribbon whenever I load the VBA Addin using Word2007 BETA 2.
I don't know why it won't work for you.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Ann Marie wrote:
Hi Greg,
I thought you might like to know that I also use Beta 2 2007 but for
some reason (beyond me) I cannot see your add-in in ADD-INS (VBA Find
and Replace - very cool) ribbon.
I use it in 2003 and it is fine - so it should load as my other
add-ins do when I load 2007 Word. It says it is loaded but it does
not show in Ribbon in ADD-INS?
Any ideas why that might be happening? I could move the code across I
guess and add to my global template - may be that will help.
Off to give this code a whirl and get this routine into test mode
with my templates in 2003.
Again, a huge thank you - they have "speed reading" and now "speed
vba" with the help of yourself Greg and Doug.
Enjoy your day ....
"Greg Maxey" <gmaxey@xxxxxxxx> wrote in message
news:1157024521.006490.8240@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ann Marie,
I didn't test in Doug's code, but to use it in Find and Replace you
would do something like:
Sub FillArrayThenFindandReplace()
Dim myArray() As String
Dim oDoc As Word.Document
Dim i As Long
Dim j As Long
Dim pRow As Long
Dim oTbl As Word.Table
Dim oRng As Word.Range
Set oDoc = Documents.Open("C:\Word List.doc")
Set oTbl = oDoc.Tables(1)
ReDim myArray(oTbl.Rows.Count - 2, 1) 'Size the array
For pRow = 2 To oTbl.Rows.Count 'Start with 2 to skip the header row
For i = 1 To 2
myArray(pRow - 2, i - 1) = Left(oTbl.Cell(pRow, i), _
Len(oTbl.Cell(pRow, i).Range.Text) - 2)
Next
Next
oDoc.Close
Set oRng = ActiveDocument.Range
For pRow = 0 To UBound(myArray)
With oRng.Find
.Text = myArray(pRow, 0)
.Replacement.Text = myArray(pRow, 1)
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
I have posted an Addin on my website that I created with the help of
Doug and others that you might be interested in:
http://gregmaxey.mvps.org/VBA_Find_And_Replace.htm
Ann Marie wrote:
Hi Greg,
I'm a little bedazzled by that one - yes it loads the array and
messages me
but how does one call that as
vFindText
vReplace
using Doug's code as find and replace?
"Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx> wrote in message
news:emAYEJIzGHA.4044@xxxxxxxxxxxxxxxxxxxxxxx
Say you had a two column table with headings "Find" and "Replace"
in a document named C:\Word List.doc
Sub FillArray()
Dim myArray() As String
Dim oDoc As Word.Document
Dim i As Long
Dim j As Long
Dim pRow As Long
Dim oTbl As Word.Table
Set oDoc = Documents.Open("C:\Word List.doc")
Set oTbl = oDoc.Tables(1)
ReDim myArray(oTbl.Rows.Count - 2, 1) 'Size the array
For pRow = 2 To oTbl.Rows.Count 'Start with 2 to skip the header
row j = j + 1 'For testing only
For i = 1 To 2
myArray(pRow - 2, i - 1) = Left(oTbl.Cell(pRow, i), _
Len(oTbl.Cell(pRow, i).Range.Text) - 2)
Next
Next
oDoc.Close
'Testing
For pRow = 0 To j - 1
For i = 0 To 1
MsgBox myArray(pRow, i)
Next
Next
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
jjacobs13@xxxxxxxxx wrote:
How does one go about copying the words into the Array (from
another document and/or pasted into the beginning)?
Thank you for sharing your knowledge.
Doug Robbins - Word MVP wrote:
Use the following type of construction:
Dim vFindText As Variant
Dim vReplText As Variant
Dim sFindText As String
Dim sReplText As String
Dim i As Long
vFindText = Array("one", "two", "three", "four", "five")
vReplText = Array("six", "seven", "eight", "nine", "ten")
For i = LBound(vFindText) To UBound(vFindText)
sFindText = vFindText(i)
sReplText = vReplText(i)
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = False
.Text = sFindText
.replacement.Text = sReplText
.Execute Replace:=wdReplaceAll
End With
Next i
Or you could put the words to be found in one column of a table
and replacements words in the second column and then iterate
through the rows of the tables, getting the words our of each
column and using them for the sFindText and sReplText in the
above. --
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself
of my services on a paid consulting basis.
Doug Robbins - Word MVP
<jjacobs13@xxxxxxxxx> wrote in message
news:1156697782.606590.275760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I guess the words don't have to be pasted at the beginning of
the document. Perhaps just copied/pulled from another Word
document.
.
- References:
- Re: Macro for Mass Find and Replace
- From: Greg Maxey
- Re: Macro for Mass Find and Replace
- Prev by Date: Re: Macro for Mass Find and Replace
- Next by Date: Making email links "active"?
- Previous by thread: Re: Macro for Mass Find and Replace
- Next by thread: Re: Macro for Mass Find and Replace
- Index(es):
Relevant Pages
|