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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching strings 1

Status
Not open for further replies.

RonRepp

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

Working with VBA on a PowerPoint project. I need to go btwn the tags and bold, italicize, underline as needed. Here is the code for the bold so far. It works great for the first instance, but after that...PFT! I know it's counting the tags properly, because I've gone through and counted them by hand.

Code:
Public Sub StartBoldProcess(ByVal sCharacter As String, ByVal EndCharacter As String)
Dim strLine As String
Dim BegPos As Integer
Dim NewPos As Integer
Dim EndPos As Integer
Dim Found As Boolean
Dim NewString As String
Dim i As Integer
Dim Lngth As Long


Set ActiveSlide = PP.ActivePresentation.Slides(124)

strLine = ActiveSlide.Shapes("Textbox 3") _
                .TextFrame.TextRange.Text
For i = 1 To Len(strLine)

BegPos = FindStartPosition(strLine, sCharacter, 1)
If BegPos > 0 Then
    Found = True
    EndPos = FindEndPosition(strLine, EndCharacter, BegPos)
        If EndPos > 0 Then
            Found = True
            RemPos = EndPos
            EndPos = BegPos + EndPos - 1
            If IsBold Then
                BoldSelection BegPos + 3, EndPos
                'ReplaceTags EndPos, EndPos + 3, EndBold, ""
                'ReplaceTags BegPos, EndPos, sCharacter, ""
                'RemPos = EndPos '- 7
                Debug.Print "SlideNumber " & ActiveSlide.SlideNumber & ": BegPos " & BegPos & ": EndPos " & EndPos '& ": RemPos " & RemPos
                
            End If
                
        End If
End If
Next i
End Sub



Public Function FindStartPosition(ByVal strLine As String, ByVal String2Find, ByVal BegPos As Integer) As Integer
Dim POS1 As Integer
Dim Found As Boolean
POS1 = InStr(BegPos, strLine, String2Find, vbTextCompare)
    If POS1 > 0 Then
        Found = True
        FindStartPosition = POS1
    Else
        Found = False
    End If
End Function
Public Function FindEndPosition(ByVal strLine As String, ByVal String2Find, ByVal BegPos As Integer) As Integer
Dim POS1 As Integer
Dim Found As Boolean
Dim strNew As String

        strNew = Mid(strLine, BegPos + 3, Len(strLine))
        POS1 = InStr(BegPos, strNew, "<", vbTextCompare)
        If POS1 > 0 Then
            Found = True
        Else
            Found = False
        End If
        
        If Found Then
            strReturn = Mid(strNew, BegPos, POS1 - 1)
            RemPos = POS1 - 1
            Debug.Print "End Pos: SlideNumber" & ActiveSlide.SlideNumber & ": RemPos " & RemPos
            
            FindEndPosition = POS1 - 1
        End If
End Function

Any help will be greatly appreciated.


Ron Repp

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

My newest novel: Wooden Warriors
 
hi,

Maybe tell us in prose, what it is that you intend the process to do.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi, Skip:

I want to find the HTML tags (<b>, </b>) and then bold the text between them, then remove the tags. It only works for the first instance. After that, it bolds substrings that don't have the tags. There may be several instances of BOLD within the text.

Ron Repp

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

My newest novel: Wooden Warriors
 
Please post a representative sample of HTML / text that your code both works and fails to work on, explaining what your results are for the representative sample.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Here you go. I eliminate the <li>, <ul> and their end tags before it goes onto a PowerPoint slide.

Code:
<li><b>Paint Condition</b> - Check the condition of the paint on each drum. Reject the drum if it needs to be painted
<li><b>Dents</b> - Check the number and depth of dents on each drum. As a guide if you count no more than six dents and each is less than one-half of an inch deep, you can use the drum. If you count no more than four dents and each is less than 1inch deep, you can use the drum if the dents can be removed without weakening the metal or container construction. Reject a drum as when dents over one-half of an inch long are present along the chime, when dents have caused the metal to rupture, or when dents exceed in number or depth the limits set above
<li><b>Contamination</b> - Check the interior of each drum for general cleanliness. Drums containing removable contaminates should be cleaned thoroughly before they are used. Label a drum as non-useable if it contains an unknown residue or a similar substance that you cannot remove
<li><b>Rust</b> - Check the inside and outside of each drum for rust. The drum must be rejected if there are excessive amounts of exterior rust. The inside of the drum must be free of loose rust before the drum can be used
<li><b>Holes</b> - Check each drum carefully for holes. A hole, rip, or rupture anywhere in the drum makes it non-repairable. Any signs of holes reject the drum
<li><b>Flange</b> - Check the condition of the flange on each drum. Ensure it is securely seated in the head and that the flange threads are in good condition. Drums with crossed, stripped, rusted, or worn flange threads are classified as non-repairable and must be rejected
<li><b>Bungs</b> - Check each drum for missing or defective bungs and seals. Reject the drum if bungs threads are damaged or if manufacturer approved bungs and seal are available replace the bung and seal


Ron Repp

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

My newest novel: Wooden Warriors
 
Skip:

Sorry, I missed the last portion of what you said. I replace the <li> tags with • before it ever hits the slide. Same with the other tags like <li=small circle> tag. This HTML is in Excel, and w/help from PHV, Combo and StrongM, actually could paste the HTML on the slide, but it's not real HTML. It looks different on the slide than it would if basted into an HTML file. So, I replace the bullets first and worry about bold, italics and underline on the slide, where I can use PP's formatting.

What I get is the first instance of <b> is bolded and the tags removed. I assumed that I could do this through a loop, but the positions of StartCharacter and EndCharacter are off. It finds the next <b> fine, but for some reason, the substring to be bolded runs beyond the end tag.

Ron Repp

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

My newest novel: Wooden Warriors
 

this loops thru each slide and shape, but you will have to delete the html when finished
Code:
Sub Main()
    Dim p1 As Integer, p2 As Integer, oSLide As Slide, oShape As Shape
    
    For Each oSLide In ActivePresentation.Slides
        For Each oShape In oSLide.Shapes
            With oShape.TextFrame.TextRange
                p2 = 0
                
                Do
                    p1 = InStr(p2 + 1, .Text, "<b>")
                    If p1 = 0 Then Exit Do
                    p2 = InStr(p1 + 1, .Text, "</b>")
                    
                    .Characters(p1 + 3, p2 - p1 - 3).Font.Bold = True
                Loop
            End With
        Next
    Next
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Excellent. Thanks Skip. I think I should stick with writing over coding.

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