Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-08-2020, 03:18 AM
alex100 alex100 is offline Find/Replace text longer than 255 characters Windows 7 64bit Find/Replace text longer than 255 characters Office 2016
Advanced Beginner
Find/Replace text longer than 255 characters
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Find/Replace text longer than 255 characters

I am trying to replace certain tags with text that is longer than 255 characters. I found two possible solutions...

1) Greg Maxey's solution which involves copying/pasting data to clipboard. It's using '^c' in the 'Replacement.Text' instruction, as following:

.Replacement.Text = "^c"

source: Find & Replace (w\Long Strings)

I already implemented this solution, and it works great, but the problem is that in the end, the original clipboard content is lost. One way to overcome this problem is to save the original clipboard and then have it restored after the replacement code is run. I did that, and it works good for text content. But I have not found a solution to save and restore binary clipboard data!

Is there a way to do that in VBA, please? I'm referring to saving and restoring binary clipboard data, not just text.

2) I also found this code that uses .TypeText instead of .Replacement. You can use it with content that's longer than 255 characters.

Code:
With ActiveDocument.ActiveWindow.Selection
    .WholeStory
    .Find.ClearFormatting
    .Find.Execute FindText:="Whatever you want to replace"
    Options.ReplaceSelection = True
    .TypeText Text:="Type away to your heart's content..."
End With
source: vba - runtime error 5854 string parameter is too long - Stack Overflow

The problem is that at times it works ok, but most of the times it doesn't. For example, if you only have very little content inside the document (few words, basically), it works good. But if you have two or three pages, then what it does is to have the new text content inserted at the top of the document, not where the FindText content is located.

I think this second solution could work great too, with only a few adjustments to the code.

If anyone could help me, that would be great and much appreciated.

Thank you,



Alex
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/Replace text longer than 255 characters Combining Characters in Find & Replace Surge Word 6 03-10-2020 12:42 AM
Find/Replace text longer than 255 characters Insert text longer 254 characters in word Esgrimidor Word VBA 7 03-16-2017 01:02 PM
Find/Replace text longer than 255 characters Find & Replace tool no longer comes up Literalman Word 3 07-13-2015 03:07 PM
Find/Replace text longer than 255 characters Find and Replace some characters with Bullets kjxavier Word 1 01-02-2015 12:15 AM
Find and replace No longer work TJH Word 3 03-25-2014 11:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:36 PM.


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