![]() |
#1
|
|||
|
|||
![]()
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 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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Surge | Word | 6 | 03-10-2020 12:42 AM |
![]() |
Esgrimidor | Word VBA | 7 | 03-16-2017 01:02 PM |
![]() |
Literalman | Word | 3 | 07-13-2015 03:07 PM |
![]() |
kjxavier | Word | 1 | 01-02-2015 12:15 AM |
Find and replace No longer work | TJH | Word | 3 | 03-25-2014 11:33 PM |