PDA

View Full Version : [SOLVED:] Split out text colour in the same TextFrame



Faridwahidi
06-09-2015, 01:41 AM
Hi,

Can anyone help me?
I want to change color for only newline (2nd Line) but the code below will change all text to red color :crying:



mySlide.Shapes(1).TextFrame.TextRange.Text = "SUMMARY OF AAs RECEIVED AND ACCREDITED " & vbNewLine & "JANUARY - MONTHS-20XX"
mySlide.Shapes(1).TextFrame.TextRange.Font.Size = 16
mySlide.Shapes(1).TextFrame.TextRange.Font.Bold = True
mySlide.Shapes(1).TextFrame.TextRange.Font.Color = RGB(255, 0, 0)

John Wilson
06-09-2015, 02:45 AM
Maybe this:



Dim oTR as TextRange

mySlide.Shapes(1).TextFrame.TextRange.Text = "SUMMARY OF AAs RECEIVED AND ACCREDITED " & vbNewLine & "JANUARY - MONTHS-20XX"
mySlide.Shapes(1).TextFrame.TextRange.Font.Size = 16
mySlide.Shapes(1).TextFrame.TextRange.Font.Bold = True
Set oTR=mySlide.Shapes(1).TextFrame.TextRange.Lines(2)
oTR.Font.Color.RGB = RGB(255, 0, 0)

Faridwahidi
06-09-2015, 02:57 AM
Hi john wilson,

Thanks a lot.

Any idea to change in between text? e.g. If I want "JANUARY -" remain on black colour and only "MONTHS-20XX" turn to red

John Wilson
06-09-2015, 03:19 AM
You would need to deduce the position of the -

Like this (and then you need to play with the code)


Sub FixTxt()
Dim mySlide As Slide
Dim otxR1 As TextRange
Dim otxR2 As TextRange
Dim hyphPos As Integer
Dim lenTR As Long
Set mySlide = ActivePresentation.Slides(1)
mySlide.Shapes(1).TextFrame.TextRange.Text = "SUMMARY OF AAs RECEIVED AND ACCREDITED " & vbNewLine & "JANUARY - MONTHS-20XX"
lenTR = mySlide.Shapes(1).TextFrame.TextRange.Length
hyphPos = InStr(1, mySlide.Shapes(1).TextFrame.TextRange.Text, "-")
mySlide.Shapes(1).TextFrame.TextRange.Font.Size = 16
mySlide.Shapes(1).TextFrame.TextRange.Font.Bold = True
hyphPos = InStr(1, mySlide.Shapes(1).TextFrame.TextRange.Text, "-")
Set otxR1 = mySlide.Shapes(1).TextFrame.TextRange.Characters(Start:=1, Length:=hyphPos + 1)
Set otxR2 = mySlide.Shapes(1).TextFrame.TextRange.Characters(Start:=hyphPos + 1, Length:=lenTR - hyphPos)
otxR1.Font.Color.RGB = RGB(0, 0, 0) 'or whatever
otxR2.Font.Color.RGB = vbRed
End Sub

Faridwahidi
06-09-2015, 06:31 PM
Hi John,

Thanks A lot. hope top learn more from you in future.

Instead of Range.Characters(), I think, we may also use Left/Right/Len function?