PDA

View Full Version : textrange.text with multiple colors



mtec80
12-03-2015, 01:31 AM
Hi guys,

I'm trying to insert the value of an userform as a textbox in powerpoint.
This works fine so far but I must declare specific words in this textbox in specific colors.
I've tried this with the TextRange.Words method but my problem is, that the output is a mix of static words and variable content from the free text forms from the user form.
Here's my code:

Private Sub CommandButton1_Click()


'--Declare Dimensions "Slide" and "Shape"
Dim Sld As Slide
Dim Shp As Shape


'--Setup function to use current active slide
Set Sld = Application.ActiveWindow.View.Slide


'--Declare Shape, related size, color and line
Set Shp = Sld.Shapes.AddShape(msoShapeRectangle, 10, 10, 300, 140)
Shp.Fill.ForeColor.RGB = RGB(255, 255, 255)
Shp.Line.Visible = msoTrue


'--Area to define Text Box value
Shp.TextFrame.TextRange.Text = ( _
(TextBox7.Value) & " Image" & vbCrLf & _
("Element ID: ") & vbTab & (TextBox1.Value) & vbCrLf & _
"Descritpion: " & vbTab & TextBox2.Value & vbCrLf & _
"Default: " & vbTab & TextBox3.Value & vbCrLf & _
"Editable: " & vbTab & ComboBox1.Text & vbCrLf & _
"Img Width: " & vbTab & TextBox4.Value & vbCrLf & _
"Img Height: " & vbTab & TextBox5.Value & vbCrLf & _
"If Empty?: " & vbTab & ComboBox2.Text & vbCrLf & _
"Notes: " & vbTab & TextBox6.Value)






Shp.TextFrame.TextRange.Words(1, 2).Font.Color.RGB = RGB(0, 0, 0)
Shp.TextFrame.TextRange.Words(3, 4).Font.Color.RGB = RGB(192, 0, 0)
Shp.TextFrame.TextRange.Words(5).Font.Color.RGB = RGB(192, 0, 0)
Shp.TextFrame.TextRange.Words(6).Font.Color.RGB = RGB(0, 0, 0)
Shp.TextFrame.TextRange.Words(7, 8).Font.Color.RGB = RGB(192, 0, 0)
Shp.TextFrame.TextRange.Words(9).Font.Color.RGB = RGB(192, 0, 0)
Shp.TextFrame.TextRange.Words(6).Font.Color.RGB = RGB(0, 0, 0)




Shp.TextFrame.TextRange.Words(1, 2).Font.Bold = msoCTrue




'--Declare format of Text Box
'--hp.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
Shp.TextFrame.AutoSize = ppAutoSizeShapeToFitText
Shp.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignLeft
Shp.TextFrame.TextRange.Font.Size = 10
Shp.TextFrame.TextRange.Font.Name = "Century Gothic"




Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim objControl As Control
For Each objControl In Controls
Select Case TypeName(objControl)
Case "TextBox"
objControl.Text = ""
Case "ComboBox"
objControl.Value = ""
Case "OptionButton", "CheckBox"
objControl.Value = False
End Select
Next
End Sub


I must export the static value ( like "Element ID: ") in red color, the rest should be black.
How can I realize that?

Thank you in advance for your help!!!