![]() |
#1
|
|||
|
|||
![]()
I was trying to put formatted text into a dictionary.
I got it to work using Selection.FormattedText or putting the selection into a Range. I verified that by putting the selection/range into a new document using my dictionary and the key that went with it. However, if I close the original document, while dictionary.count still shows the correct number of items, when I try to put it into a document it errors out. I thought that once I put either Selection.Formatted text or a range into a dictionary it would exist in the dictionary even it the original document was closed. But that doesn't seem the case. I endup writing the text to an RTF and then inserting that, but if there was any way I could store the formatted text, a/k/a "rich text" into a dictionary that would be much preferred. I created a blank document and then typed some "rich text" (This is bold, this is underlined), etc. and selected it. Then I ran this sub: Dim dicTest as Object Dim rng1 as Range Set dicTest = CreateObject("Scripting.Dictionary") Set dicTest(1) = Selection.FormattedText 'Had to use "Set" go keep it as FormattedText Set rng1 = Selection.FormattedText Set dicTest(2) = rng1.FormattedText Documents([Put in # or name of a blank document]).Activate Selection.FormattedText = dicTest(1) or Selection.FormattedText = dicTest(2). Either of those work, BUT if I close document 1 then trying to put either dicTest 1 or 2 into a document will fail. Is there any way to store formatted text in a dictionary or another variable/object? |
Tags |
dictionaries, dictionary, formatted text |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... | Ddadoo57 | Word VBA | 18 | 02-13-2023 12:25 PM |
![]() |
reidtaylor | Mail Merge | 7 | 05-07-2019 04:19 AM |
Hyperlinks that Do Not Exist in the Original Word Document Appearing in the PDF Document | diarrheaofthewprocessor | Word | 11 | 01-24-2017 01:52 PM |
![]() |
DanNatCorning | Word VBA | 1 | 04-29-2016 10:47 PM |
Selection (range) in Word or Excel table | NobodysPerfect | Word VBA | 2 | 09-16-2014 12:06 AM |