![]() |
|
#1
|
|||
|
|||
|
Hi guys,
I am trying to write a Macro to replace a string of text with another one, but I receive an error for the text to replace - run time error 5854 - string parameter is too long. I know that the string has more than 255 characters, but I cannot change it and I cannot split it in 2 commands. Code it like below: Let Address2 = "{Insert shop address}" Let Localizedaddress1 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = Address2 .Replacement.Text = Localizedaddress1 .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Can you please help with how should I modify it in order to work? Thank you! Irina |
|
#2
|
||||
|
||||
|
You could split it e.g.
Code:
Dim Address2 As String
Dim Localizedaddress1 As String, Localizedaddress2 As String
Dim oRng As Range
Address2 = "{Insert shop address}"
Localizedaddress1 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
Localizedaddress2 = "xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=Address2)
oRng.Text = Localizedaddress1 & Localizedaddress2
oRng.Collapse 0
Loop
End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thanks! It works great
![]() Now I have an additional question, since one problem is fixed, another one arises ))Is there a way to add something to the above macro for the text to be replaced and appear in word like this (on line under the other, not on the same line): xxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxx Thank you so much for your help with this! I have struggled with research on this the whole day
|
|
#4
|
|||
|
|||
|
Solved it with & vbNewLine &
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| inputing japanese string in word's macro = ?? | tyki | Word VBA | 0 | 02-29-2016 03:09 AM |
How to give multiple styles while inserting string
|
PRA007 | Word VBA | 4 | 01-18-2016 12:00 AM |
| One long string of text with ; as the delimiter | Laurie B. | Excel | 1 | 02-28-2015 03:02 AM |
Macro to create new word doc and save the file using String found in the document
|
VBNation | Word VBA | 2 | 02-08-2013 07:14 AM |
| Renaming Word Formfields: string too long error | silverspr | Word VBA | 7 | 01-22-2013 06:20 PM |