How to overcome VBA ms.word-replace-macro 255 limitation
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!
Code:
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
Re: How to overcome VBA ms.word-replace-macro 255 limitation
where did you get this Macro From ?
the property for
vb Code:
.replacement.Text
is the issue. i would imagine that you will need to code some sort of replace function to overcome this as it seems like a restriction with selection object.
i'm sure there will be some samples of how to find an replace data in word on here try a search.
Re: How to overcome VBA ms.word-replace-macro 255 limitation
One logic (untested) that you can follow is
1) Split the replacement string in two parts
2) Replace the Search string with the first part of the replacement string
3) Now search for the first part of the replacement string and add (not replace) the 2nd string to it...
Hope I make sense...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Re: How to overcome VBA ms.word-replace-macro 255 limitation
Hi,
If you can find and erase the text, your pointer should still be in the documents range? If it is, you can inserttext at a point in the range, which should be the >255 characters you want.
Not sure if this makes sense... hehe but might be another option?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Re: How to overcome VBA ms.word-replace-macro 255 limitation
Originally Posted by Ecniv
Hi,
If you can find and erase the text, your pointer should still be in the documents range? If it is, you can inserttext at a point in the range, which should be the >255 characters you want.
Not sure if this makes sense... hehe but might be another option?
But interesting enough! how do i insert text after a replacement? I'tried to select.typetext "xxx" but the "xxx" print appeared on the top of the document.
Can you provide a sample code that words with my "replacer" function?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...