0

Aim: To adjust Font size of group of words in a single textbox in PowerPoint.

Details:

I have two lists:

Labels = ["Mahon Point Retail","Park","Blackpool Drive","Balance","Finglas Point"] 
FontSize = [10,23,15,20,40]

I would like to apply the font sizes in FontSize to the labels in Labels, by their indexes.

My script:

#add all items in Labels to a single textbox
for i, label in enumerate(labels):
     Shape.TextFrame.TextRange.Text += "  " + label 

#apply font size from FontSize list to its corresponding label
for x, num in enumerate(FontSize, 1):
     Shape.TextFrame.TextRange.Words(x).Font.Size = int(num)

The PROBLEM:

I believe the problem lies with the use of "Words(x)" property, is there any way I can define what a word is? It treats "Mahon Point Retail" as three words but I would like to treat it as a single word.

Community
  • 1
  • 1
Boosted_d16
  • 13,340
  • 35
  • 98
  • 158

1 Answers1

1

Can't help with the Python part, but you can probably adapt this VBA to do what you want. First a function to set the desired formatting for any substring, then a test subroutine. This will only change the first instance of the word(s) within the string. Calling it repeatedly from within a loop that tests for the presence of the string within the larger string would solve that.

Function FontTheWords(oSh As Shape, sWords As String)

    Dim oRng As TextRange
    ' Get a range object representing the chosen words
    Set oRng = oSh.TextFrame.TextRange.Characters(InStr(oSh.TextFrame.TextRange.Text, sWords), Len(sWords))
    Debug.Print oRng.Text
    ' format the range in whatever way you like
    With oRng.Font
        .Bold = True
        .Color.RGB = RGB(255, 0, 0)
    End With

End Function

Sub TestIt()
    FontTheWords ActiveWindow.Selection.ShapeRange(1), "Blackpool Drive"
End Sub
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34