View Single Post
 
Old 08-29-2023, 04:59 PM
skarden skarden is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 26
skarden is on a distinguished road
Question Word Range/Selection exist if document is closed?

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?
Reply With Quote