Making Some part of text entered in Shapes Bold and increase its font size.

ashni

New Member
Joined
Jun 13, 2016
Messages
32
Hello!!
I have this code to insert some information in shapes.
Code:
Selection.ShapeRange.TextFrame2.TextRange.Characters.text = "ID: " & GetWiId & vbNewLine & "Title: " & title & vbNewLine & "Completed work :" & GetWiCompleted & vbNewLine & "Remaining work :" & GetWiRemaining

I want it to appear in the shape as:-

ID: 1604449
Title: When Review marker tool is on blow-up shows exception
Completed work :7
Remaining work :4
[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]Can i do it? Some part in bold some part no bold..Thanks in advance[/TD]
[/TR]
</tbody>[/TABLE]
 
Try...

Code:
[color=darkblue]Dim[/color] vLabels [color=darkblue]As[/color] [color=darkblue]Variant[/color]
[color=darkblue]Dim[/color] Pos [color=darkblue]As[/color] [color=darkblue]Integer[/color]
[color=darkblue]Dim[/color] i [color=darkblue]As[/color] [color=darkblue]Integer[/color]

vLabels = Array("ID:", "Title:", "Completed work:", "Remaining work:")

[color=darkblue]With[/color] Selection.ShapeRange.TextFrame2.TextRange
    .Characters.Text = "ID: " & GetWiId & vbNewLine & "Title: " & Title & vbNewLine & "Completed work: " & GetWiCompleted & vbNewLine & "Remaining work: " & GetWiRemaining
    Pos = 0
    [color=darkblue]For[/color] i = 0 [color=darkblue]To[/color] [color=darkblue]UBound[/color](vLabels)
        Pos = InStr(Pos + 1, .Text, vLabels(i))
        [color=darkblue]If[/color] Pos > 0 [color=darkblue]Then[/color]
            .Characters(Pos, Len(vLabels(i))).Font.Bold = [color=darkblue]True[/color]
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] i
[color=darkblue]End[/color] [color=darkblue]With[/color]

Hope this helps!
 
Upvote 0
Thanks dominic for replying !!
But the code is not working. No part is bold . It is still Appearing as :

ID: 24453454
Title: ASDASDF tyg g brtuytyj h
Completed work: 7
Remaining work: 4

 
Upvote 0
It seems that the TextRange.Text returns an empty string because the shape text doesn't take until the macro is exited

Try this variation : (code addition in red)

Code:
Sub Test()
    Dim vLabels As Variant
    Dim Pos As Integer
    Dim i As Integer
    
    vLabels = Array("ID:", "Title:", "Completed work:", "Remaining work:")
    With Selection.ShapeRange.TextFrame2.TextRange
        .Characters.Text = "ID: " & GetWiId & vbNewLine & "Title: " & Title & vbNewLine & "Completed work: " & GetWiCompleted & vbNewLine & "Remaining work: " & GetWiRemaining
[B][COLOR=#ff0000]        If Len(.Characters.Text) = 0 Then Call Test: Exit Sub[/COLOR][/B]
        Pos = 0
        For i = 0 To UBound(vLabels)
            Pos = InStr(Pos + 1, .Text, vLabels(i))
            If Pos > 0 Then
                .Characters(Pos, Len(vLabels(i))).Font.Bold = True
            End If
        Next i
    End With
End Sub
 
Last edited:
Upvote 0
Okay, I thought I'd take another look at this. It seems that if we don't refer to the Characters object when setting the text, we won't have a problem...

Code:
[COLOR=darkblue]Dim[/COLOR] vLabels [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
[COLOR=darkblue]Dim[/COLOR] Pos [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR]
[COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR]

vLabels = Array("ID:", "Title:", "Completed work:", "Remaining work:")

[COLOR=darkblue]With[/COLOR] Selection.ShapeRange.TextFrame2.TextRange
    .Text = "ID: " & GetWiId & vbNewLine & "Title: " & Title & vbNewLine & "Completed work: " & GetWiCompleted & vbNewLine & "Remaining work: " & GetWiRemaining
    Pos = 0
    [COLOR=darkblue]For[/COLOR] i = 0 [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](vLabels)
        Pos = InStr(Pos + 1, .Text, vLabels(i))
        [COLOR=darkblue]If[/COLOR] Pos > 0 [COLOR=darkblue]Then[/COLOR]
            .Characters(Pos, Len(vLabels(i))).Font.Bold = [COLOR=darkblue]True[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR] i
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top