How to overcome VBA ms.word-replace-macro 255 limitation

A

Afterthought

Hi all,

I've been searching for a solution for this problem for days.
I'm not using the vba replace function instead I'm using the word
replace macro.

Problem is this macro will not accept text exceeding 255 characters.
Note: Line 6 where value inserted to "replacement.text" assigned to
"replacement_"
And error occurs in this scenario.

Is there a way to insert more than 255 characters using the ms.word-
replace macro below?
I need to use the ms.word-replace macro below, because it can insert
the data in right places in the document.

Please help me on this, thanks!

Word Replace Macro
================
Private Sub Replacer(target_, replacement_)
'Dim replacement_ As Long

With Selection.Find
.Text = target_
.replacement.Text = replacement_ <---------------------Error
Prompt - String too Long
.replacement.Font.Hidden = False
.Execute Replace:=wdReplaceOne, Forward:=True
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With

Call StartPointer
End Sub
 
D

Doug Robbins - Word MVP

Copy the replacement text to the clipboard, and then run a macro containing
the following code when the document in which you want to make the
replacements is the active document.

Dim target As String
Dim rngtarget As Range
target = InputBox("Enter the text that you want to be replaced.")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=target, Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Selection.Paste
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
Loop
End With


--
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, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top