Change Font color in Smart Art Chart

User avatar
Stefan_Sand
4StarLounger
Posts: 412
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Change Font color in Smart Art Chart

Post by Stefan_Sand »

Hello, i have a nice tool where i can adopt most of a smart art chart by cell values and colors.
But for some unknown reason, i cannot Change font Color and style adopting the Code for "root nodes"

For example:
' Set root node properties
Set QNode = QNodes(1)
With QNode.TextFrame2.TextRange
.Text = Range("B2").Value
.Font.Fill.ForeColor.RGB = vbBlack 'alt vbBlack
.Font.Size = UE
.Font.Bold = True 'Style = "Fett / Bold"

and the child nodes:
'Set Children
With QChild.TextFrame2.TextRange
.Text = Range("B" & r).Value
.Font.Fill.ForeColor.RGB = Range("C" & r).Font.Color
.Font.Size = RE
.Font.Italic = Range("C" & r).Font.Italic



If i want to change

.Font.Fill.ForeColor.RGB = vbBlack in the root node to .Font.Fill.ForeColor.RGB = Range("C" & r).Font.Color
i get an error. And i don´t know why, it only says the rang method is wrong…

does someone know, if this happens, because it is impossible to change the color and behavior of a root node by code?

Thanks,
Stef
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change Font color in Smart Art Chart

Post by HansV »

Could you attach a sample workbook? Thanks in advance.
Best wishes,
Hans

User avatar
Stefan_Sand
4StarLounger
Posts: 412
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Re: Change Font color in Smart Art Chart

Post by Stefan_Sand »

here it is
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change Font color in Smart Art Chart

Post by HansV »

Thanks!
At that point in the code, the variable r hasn't been assigned a value yet, so r = 0. Range("C0") doesn't exist, hence the error.
You can use

Code: Select all

    ' Set root node properties
    Set QNode = QNodes(1)
    With QNode.TextFrame2.TextRange
        .Text = Range("B2").Value
        .Font.Fill.ForeColor.RGB = Range("C2").Font.Color
        .Font.Size = UE
        .Font.Bold = True 'Style = "Fett / Bold"
    End With
Remark: currently, the font color of C2 is set to white, so you'd get white text on a yellow background. That is hard to read!
Best wishes,
Hans

User avatar
Stefan_Sand
4StarLounger
Posts: 412
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Re: Change Font color in Smart Art Chart

Post by Stefan_Sand »

Ok, ist definitely so with the start root node in c2, but with the other root nodes below, if i define it, it would be possible to use the variable r?

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change Font color in Smart Art Chart

Post by HansV »

Yes! See the attached version.

Eileens Test.xlsm
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
Stefan_Sand
4StarLounger
Posts: 412
Joined: 29 Mar 2010, 11:50
Location: Vienna, Austria

Re: Change Font color in Smart Art Chart

Post by Stefan_Sand »

Perfect! i only had to take C & r, and after testing it, works like a charm. Thank You!