Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-29-2023, 04:59 PM
skarden skarden is offline Word Range/Selection exist if document is closed? Windows 10 Word Range/Selection exist if document is closed? Office 2010 64bit
Novice
Word Range/Selection exist if document is closed?
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 27
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
 

Tags
dictionaries, dictionary, formatted text



Similar Threads
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
Word Range/Selection exist if document is closed? Word crashes if the merged document file is closed first 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
Word Range/Selection exist if document is closed? Name a Range in a Word Document and then copy that range to the end of the doc w button click 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:35 AM.


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