Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2019, 02:59 AM
irinarox irinarox is offline Word Macro give errror that string is too long - how to fix it Windows 10 Word Macro give errror that string is too long - how to fix it Office 2016
Novice
Word Macro give errror that string is too long - how to fix it
 
Join Date: May 2019
Posts: 9
irinarox is on a distinguished road
Default Word Macro give errror that string is too long - how to fix it

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
Reply With Quote
  #2  
Old 11-21-2019, 05:10 AM
gmayor's Avatar
gmayor gmayor is offline Word Macro give errror that string is too long - how to fix it Windows 10 Word Macro give errror that string is too long - how to fix it Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 11-21-2019, 05:55 AM
irinarox irinarox is offline Word Macro give errror that string is too long - how to fix it Windows 10 Word Macro give errror that string is too long - how to fix it Office 2016
Novice
Word Macro give errror that string is too long - how to fix it
 
Join Date: May 2019
Posts: 9
irinarox is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 11-21-2019, 06:20 AM
irinarox irinarox is offline Word Macro give errror that string is too long - how to fix it Windows 10 Word Macro give errror that string is too long - how to fix it Office 2016
Novice
Word Macro give errror that string is too long - how to fix it
 
Join Date: May 2019
Posts: 9
irinarox is on a distinguished road
Default

Solved it with & vbNewLine &
Reply With Quote
Reply

Thread Tools
Display Modes


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
Word Macro give errror that string is too long - how to fix it 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
Word Macro give errror that string is too long - how to fix it 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:37 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft