Re: Macro for Mass Find and Replace

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.




.



Relevant Pages

  • Re: LinkButton Event Handling (Dynamic controls)
    ... which is run on the page load and every grid ... postback. ... on page init not on page load. ... Dim loCurrentPage As New Literal ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Datagrid question
    ... Are you sure that you are using a Datagrid, you are talking in your text about a DataGridViewRow, you cannot use the latter in a DataGrid. ... I load the grid and display the results. ... Dim dtTempData As New DataTable ... Private Sub cmdFindCrushingRun_ClickHandles cmdFindCrushingRun.Click ...
    (microsoft.public.dotnet.languages.vb)
  • Datagrid question
    ... I load the grid and display ... Dim dtTempData As New DataTable ... 'load the data on the tab page by calling the appropriate load data function ... Private Sub cmdFindCrushingRun_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Drop down form field- filling large list without client-side VBA?
    ... the list in a drop down formfield is limited to 25 items. ... Dim ddList As Variant ... dropdown control with VBA... ... I'm just looking for a fast way to load the items- is ...
    (microsoft.public.word.docmanagement)
  • Re: Handle of running application
    ... The transit web site will not load the reply page, it always crashes. ... I will endeavor to get familiar with HttpWebRequest and HttpWebResponse. ... In the top right corner of this page you will see "Today's Bus Stop Schedule". ... Dim bsRoute As String ...
    (microsoft.public.dotnet.framework)