View Single Post
 
Old 08-30-2023, 06:29 AM
skarden skarden is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 27
skarden is on a distinguished road
Unhappy

Unfortunately, as I suspected, and you confirmed, a range is only a pointer, not what is in the range itself. I verified it with this macro:

Sub FormattedTextAsRangeTest()

'This proves that storing a range to a dictionary only stores a pointer to the range
'NOT what was in the range itself
'This proves it because we do not tell the dictionary to change what is stored in it (i.e. rng1)
'
'Be sure to start in a document with some formatted text
'and to set sBlankDocName to the name of an empty document

Dim dicTest As Object

Dim rng1 As Range

Dim sAdName As String
Dim sBlankDocName As String

sBlankDocName = "[Name of blank document here]"

sAdName = ActiveDocument.Name

Set dicTest = CreateObject("Scripting.Dictionary")

Selection.WholeStory

Set rng1 = Selection.FormattedText

Set dicTest(1) = rng1.FormattedText

Documents(sBlankDocName).Activate

Selection.FormattedText = dicTest(1)

Documents(sAdName).Activate

Selection.MoveLeft , 1

Selection.TypeText "Newly Added "

Documents(sBlankDocName).Activate

Selection.FormattedText = dicTest(1)

End Sub
Reply With Quote