connecting users of the CorelDRAW family of products
We take every threat seriously. CorelDRAW.com has not been affected by the Heartbleed security bug.

Problem for the VBA experts

rated by 0 users
Not Answered This post has 0 verified answers | 7 Replies | 0 Followers

Share  
Page 1 of 1 (8 items) | RSS

Top 10 Contributor
London UK
harryLondon posted on Mon, Nov 18 2013 7:26

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 textrange
set 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]

All Replies

Top 10 Contributor
Pigeon Forge, TN
Male
TAG - gdgmacros.com

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

Visit me at my GDGMacros website anytime!

Join me on Facebook to stay up to date with GDGMacros, Tips and Tricks for VBA Automation in CorelDraw, Discounts, specials, Free code and macros, and more cool sometimes not so relevant posts!

Top 10 Contributor
London UK

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.

Top 10 Contributor
Pigeon Forge, TN
Male
TAG - gdgmacros.com

Hi.

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:

TextRange.CopyAttributes

Sub CopyAttributes(SourceRange As TextRange)

Description

Member of TextRange

The CopyAttributes method copies the text attributes from the specified text range and applies them to the current text range.

~John

Visit me at my GDGMacros website anytime!

Join me on Facebook to stay up to date with GDGMacros, Tips and Tricks for VBA Automation in CorelDraw, Discounts, specials, Free code and macros, and more cool sometimes not so relevant posts!

Top 10 Contributor
London UK

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).Length
sDest.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.

Top 10 Contributor
Pigeon Forge, TN
Male
TAG - gdgmacros.com

Hi.

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.

~John

Visit me at my GDGMacros website anytime!

Join me on Facebook to stay up to date with GDGMacros, Tips and Tricks for VBA Automation in CorelDraw, Discounts, specials, Free code and macros, and more cool sometimes not so relevant posts!

Top 10 Contributor
Pigeon Forge, TN
Male
TAG - gdgmacros.com

Hi.

Also have you tried copy and pasting with code? If copy and paste will work manually then it should  work with code.

~John

Visit me at my GDGMacros website anytime!

Join me on Facebook to stay up to date with GDGMacros, Tips and Tricks for VBA Automation in CorelDraw, Discounts, specials, Free code and macros, and more cool sometimes not so relevant posts!

Top 150 Contributor
Cheyenne, WY
Male

Harry, 

The CopyAttributes should work, but you will need to do this for each character. This can be really slow, but here is an example:

    Dim trSource As TextRange
    Dim trDestination As TextRange

    Set trSource = ActiveSelectionRange.Shapes(1).Text.Story.Paragraphs(1)
    Set trDestination = ActiveSelectionRange.Shapes(2).Text.Story.Paragraphs(1)
    
    For i = 1 To trSource.End
        trDestination.Range(i, i).CopyAttributes trSource.Range(i, i)
    Next i

I don't recommend copy and paste often, but in this case it is much faster. Here is an example of how you can use copy and paste:

    Dim tSource As CorelDRAW.Text
    Dim tDestination As CorelDRAW.Text
    
    Set tSource = ActiveSelectionRange.Shapes(1).Text
    Set tDestination = ActiveSelectionRange.Shapes(2).Text
    
    tSource.Story.Paragraphs(1).Copy
    tDestination.BeginEdit
    ActiveLayer.Paste

-Shelby

  • Filed under:
Page 1 of 1 (8 items) | RSS
© Corel Corporation. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms and Conditions / User Guidelines.