Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing text and formatting on Powerpoint 2010 thru VBA

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

This goes back to a prior thread: thread707-1712384 in which PHV, Combo and Strongm helped. The procedure worked great, but in Powerpoint, HTML does not format the same as it does on a Web page, so the client wants some changes.

I have a PP slide with a textbox. The textbox has unformatted HTML in it, and I need to replace what's btwn the tags with formatting (i.e. bold, etc). The code below works, but goes beyond the last instance of </b> (in this case).

If the client changes his mind again, I'm gonna brain him.
Code:
Sub ReplaceText()
Dim strLine As String
Dim strNew
Dim Pos1 As Integer
Dim Pos2 As Integer
Dim Found As Boolean
Dim charRange As TextRange
Dim i As Integer
Dim NewPos As Integer
    
    Do
            strLine = Application.ActivePresentation.Slides(1).Shapes("Textbox 5") _
                .TextFrame.TextRange.Text
                
            For i = 0 To Len(strLine) - 1
            If NewPos = 0 Then NewPos = 1
                Pos1 = InStr(NewPos, strLine, "<b>", vbTextCompare)
                If Pos1 > 0 Then
                    Found = True
                Else
                    Found = False
                    Exit Sub
                End If
                If Found Then
                    Found = False
                    
                    strNew = Mid(strLine, Pos1 + 3, Len(strLine))
                    Pos2 = InStr(Pos1, strNew, "<", vbTextCompare)
                        If Pos2 > 0 Then
                            Found = True
                        Else
                            Found = False
                        End If
                End If
                
                If Found Then
                    strNew = Mid(strNew, Pos1, Pos2 - 1)

                    Application.ActivePresentation.Slides(1).Shapes("Textbox 5") _
                        .TextFrame.TextRange.Characters(Pos1 + 3, Pos2 - 1).Font.Bold = msoCTrue
                    NewPos = Pos2
                    Found = False
                Else
                    ''no bolded HTML
                    GoTo GetNextI
                End If
GetNextI:
                
            Next i
    Loop
                
                  

End Sub

Thanks,

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top