Consulting

Results 1 to 5 of 5

Thread: Split out text colour in the same TextFrame

  1. #1
    VBAX Regular
    Joined
    May 2015
    Location
    Kuala Lumpur, Malaysia
    Posts
    11
    Location

    Split out text colour in the same TextFrame

    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

    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)

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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)
    Last edited by John Wilson; 06-09-2015 at 03:02 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    May 2015
    Location
    Kuala Lumpur, Malaysia
    Posts
    11
    Location
    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

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    May 2015
    Location
    Kuala Lumpur, Malaysia
    Posts
    11
    Location
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •