Find last word and remove bold after

gailb
3StarLounger
Posts: 256
Joined: 09 May 2020, 14:00

Find last word and remove bold after

Post by gailb »

I have a textbox and would like to find the last word and remove the bold immediately after that last word. This is what I'm using, and this find the last word, but trying to add + 1 to pptTextRange.Length does not remove the bold.

Code: Select all

Sub AddEmDashToEndOfText(mySlide As Long)
    Dim pptSlide As Slide
    Dim pptShape As Shape
    Dim pptTextRange As TextRange
    
    Set pptSlide = ActivePresentation.Slides(mySlide)
    Set pptShape = pptSlide.Shapes(2)
    Set pptTextRange = pptShape.TextFrame.TextRange
    
    With pptTextRange.Characters(pptTextRange.Length)
'        .Font.Bold = msoFalse
'        .Font.Underline = msoFalse
        .InsertAfter Chr(32) & ChrW(&H2014)
    End With
End Sub

User avatar
HansV
Administrator
Posts: 78991
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Find last word and remove bold after

Post by HansV »

Could you attach a small sample presentation? I don't understand what you mean by "the bold immediately after that last word"... :sad:
Best wishes,
Hans

gailb
3StarLounger
Posts: 256
Joined: 09 May 2020, 14:00

Re: Find last word and remove bold after

Post by gailb »

Thanks Hans for your reply. Just after I posted this, I went about it from a different angle. I'm setting up a template and just changed my method to bold the text I'm specifically looking for. This works for me. Thanks again for your time.

Code: Select all

Sub BoldMe(mySlide As Long)
    Dim strFindWhat As String: strFindWhat = "Some Text"
    Dim treFind As TextRange: Set treFind = ActivePresentation.Slides(mySlide).Shapes(2).TextFrame.TextRange.Find(FindWhat:=strFindWhat)
    treFind.Font.Bold = msoTrue
    treFind.Font.Underline = msoTrue
End Sub

snb
5StarLounger
Posts: 603
Joined: 14 Nov 2012, 16:06

Re: Find last word and remove bold after

Post by snb »

Avoid redundant variables. Remember VBA is Object oriented.

Code: Select all

Sub M_snb()
   With ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
     With .Words(.Words.Count).Font
        .Bold = 1
        .Underline = 1
      End With
   End With
End Sub

gailb
3StarLounger
Posts: 256
Joined: 09 May 2020, 14:00

Re: Find last word and remove bold after

Post by gailb »

Thank you for this