If I have a paragraph text object tPara I can see the contents of the second paragraph as a textrange object at tPara.Text.Story.Paragraphs(2)
Consequently, I can take the contents of that paragraph :
dim t as textrangeset t = tPara.Text.Story.Paragraphs(2)
If I look in the debugger, I can then see that the t.Characters collection includes not only the characters themselves, but also the information associated with each character -- including fonts, attributes and font colours.
So, if I have an empty paragraph tPara2 -- why is it that a further assignment
tPara2.Text.Story.Paragraphs(1) = t
causes the paragraph text to receive only the plain text and not the associated attributes ? If the assignment is a textrange, surely the entire set of textrange objects should now be visible in tPara2, rather than just the plain text ?
[textAttributes.cdr attached for anybody who wants to check it out, the objects are referred to as sSource and sDest in the Button 1 code]
Hi.
I think it's a Draw limitation. You cannot have multiple attributes in the text string and copy them over. You would have to get the property for each character that has different properties aside from the standard single property that can be copied. Hopefully I'm wrong though.
~John
It seems a bit lopsided ... if you can create a textrange object from a paragraph (and include the various attributes within it) then you also ought to have a way to create a paragraph from a textrange.
The aim in this case is actually to exchange two paragraphs (complete with their various attributes) -- which probably ought to be as simple as swapping the pointers of the corresponding two elements. But I'm not sure if that's possible in VBA.
Open your locals window. Place a break point after you set the textrange. Run code. Then when it breaks look in your locals window and search through the properties. Try to find where there are separate properties for the parts or individual characters. I don't think there are.
Also you might try the method:
Sub CopyAttributes(SourceRange As TextRange)
Member of TextRange
The CopyAttributes method copies the text attributes from the specified text range and applies them to the current text range.
CopyAttributes sounds quite promising, assuming that attributes means the font characteristics, colour, bold etc.
I'm guessing that current text range has to be set with setRange. But adding
sDest.Text.Story.Paragraphs(1).SetRange 1, sDest.Text.Story.Paragraphs(1).LengthsDest.Text.Story.Paragraphs(1).CopyAttributes sSource.Text.Story.Paragraphs(pNumber)
is not changing any attributes in the destination.
I'm starting to wonder whether attributes means something else in this case.
Test it on a basic piece of artistic text. Just bold one letter or something.
I've never dug deep into this but never found the attributes to be able to be transferred so simply. For example if you change a font in part of the text string, this sub property or characteristic is not to be found.