Finding wild charecters in VBA ?

Premanshu

Board Regular
Joined
Oct 2, 2007
Messages
91
Hi :)

first of all please let me inform the question i am asking is about power point VBA but am not sure about the right forum to ask the question. Kindly direct me to the right place if anyone knows where i can get my answer.

I am trying to build a macro in powerpoint application which would go through all the shapes of all the slides and find particular values and highlight them.

Now the value i would be searcing for is not of fixed length for example i am looking for a hyphen (-) which has 2 numbers both at the begining and at end (i.e 12-34, 79-30..etc)
as you can see the numbers could be anything but the format would be the same. Kindly advice how can i write a macro for this.

I have a macro in word VBA which could do the above thing easily, but i am just unable to figureout a way in powerpoint. (But i hope it should be possible in powerpoint as well)

below is the code example
[code\]

Sub trial()
Options.DefaultHighlightColorIndex = wdPink
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "^#-^#"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub

[\code]

Please help...

Regards,
Premanshu
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi Jon,

Thank you for the responce :)

I tried what you gave as solution but it did not worked, May be i am not able to use it in a right way. Below is the code i have made in powerpoint VBA please advice how to make change in it. (the code i gave earlier was in word vba which is working fine)

Code:
Sub Trial2

For Each Sld In Application.ActivePresentation.Slides
     For Each Shp In Sld.Shapes
          If Shp.HasTextFrame Then
             Set TxtRng = Shp.TextFrame.TextRange
             Set FoundText = TxtRng.Find(FindWhat:= "-")
             Do While Not (FoundText is Nothing)
                  With FoundText
                        .Font.Bold = True

             Set FoundText = TxtRng.Find(FindWhat:= "-", After:= .Start + .Length - 1)
                  End with
             Loop
           End If
      Next
Next

End Sub
 
Upvote 0
Hi

If you are doing a Find & Replace then you can use this:

Find: ??-??
Replace: {leave empty}

But be careful because this will also replace e.g. 100-10 (leaving 1), so you might want to prefix and suffix with a space if it is contained within a string.
 
Upvote 0
No Jon,

I am not trying to find and replace... I am trying to find and then highlight (may be bold or any background colour) where starting 2 charecter is number then hyphen(-) then ending 2 charecter is number again.

Please help me with some code example, may be i am not able to put your given solution in a right way in powerpoint VBA.

Regards,
Premanshu
 
Upvote 0
This works for me:
Code:
Sub Trial2()
    Dim sld As Slide
    Dim shp As Shape
    Dim TxtRng As TextRange
    Dim lngChar As Long
    
    For Each sld In Application.ActivePresentation.Slides
        For Each shp In sld.Shapes
             If shp.HasTextFrame Then
                Set TxtRng = shp.TextFrame.TextRange
                With TxtRng
                    For lngChar = 1 To TxtRng.Length - 5
                        If Mid$(.Text, lngChar, 5) Like "##-##" Then
                            .Characters(lngChar, 5).Font.Bold = msoCTrue
                        End If
                    Next lngChar
                End With
              End If
         Next
    Next
End Sub

Note, I have moved this to the correct forum. :)
 
Upvote 0
Thank you so much Jon :) it works in most of the cases. I was looking for this only... but i still notice a one last problem with the code..may be if you could advice how to deal with it.

when i run the macro on my ppt file it worked perfectly fine for all the slides except for one in which i had a text box with below text in it:-


***********Text*************

Seit 1.1.96 durchgängig positive Deckungsbeiträge. Russian and Baltic with 25-30% of finnforest's main birch markets. Unternehmen mit Greenmail 1979-1983. Quelle: Klein / Rosenfeld 1988, BCG-Analyse.’
Quellen: SSK Düsseldorf; BCG Analyse. 10-15 scheduled interviews. Refine & synthesize. xxx Mrd US$. Einführung von Poison Pills bei einer Auswahl von US–Unternehmen. Anteil Firmen unter Takeover–Spekulation im Zeitpunkt der Analyse Einführung.
CAGR 93/94-96/97=2,2 %. MAK–Zahlen sind weitgehend‘ konstant' geblieben. Σ 5,5
Raum–und Baukonzept. Besuch/1st–Aufnahme der xxx bestehenden Filialen. 5,420
Tsd. DM. Equipment (z.B. xxx). Bei grossen und übergreifenden Projekten Risiko der Kostenüberschreitung hoch.
Veranlagungsprozeß:Schnittstelle PK:WP und Treasury:GRH . Rolle der Abteilung PK : WP von Treasury in Frage gestellt. um >15% p.a. KBS–fin - Kontostansabfrage.
Sparbuch umstellen auf 0-stellige (<79). Wird ein Satz bzw. eine Aufzählung mit "zum Beispiel", "z. B.," "beispielsweise", "etwa" o. Ä. eingeleitet, steht am Ende des Satzes bzw. der Aufzählung kein "etc." oder "usw."
Die wichtigsten Kunden–überwiegend Firmenkunden–wurden bereits befragt. €5,7 m - 56 % = €2,5m. xxx Kick-Off mit WL-Vorständen. Ist-Aufnahme Steuerungsmechanismen . Ausbau der gewerblichen JF, aber nur mit xxx > 2,5M oder höher. To Dos überpüfung Produktportfolio, ggf. Umstrukturierung Produktprotfolio. Anlagen-buchhaltung, Abschlüße/ Betreuung Beteiligungen.

***********Text*********

if you put this in a text box or in a shape in ppt slide and then run macro you'll notice that for the first paragraph everything works fine, then starting from the 2nd paragraph the highlighting moves to the left by 1 charecter. and every time a new paragraph start it moves to the left by one more charecter.

Can you please provide me a solution for this.... this is the only last thing i am stuck now.... this would be a veryy very big help to me.

Thank you sooooo very much for your help and support...

Also thanks again for moving me to the right forum. :)

Regards,
Premanshu
 
Upvote 0
Hello Premanshu

Did you make any amendments to the code? I tested by copying that paragraph to a text box and all of the correct components were bolded.
 
Upvote 0
No Jon, I did not make any changes to the code. I simply copy pasted the code and run it.
I have the text in the second slide of my ppt file. Not sure why it's not working in my system the way it's working on your's

Premanshu
 
Upvote 0
hello Jon,

i have figured out a way to deal with the problem, i actually found a macro on the internet which can tell me the paragraph number where my cursor is. Using this macro with your's i think i'll be able to sort it out.

Thank you very very much Jon once again for all the support and help you gave me. Also a big thanks to MrExcel website also where i always find solutions for any vba related problem i ever face.

by the way Jon i am just give the code i found on the internet for identifying the paragraph number here below, may be it if you would like to see it or anyone else who is following this thread might found this usefull:-

Code:
Sub WhichParagraphIsTheCursorOn()

'Determines the current cursor position in the selection
'(Also counts number of paragraphs selected)
'(Will NOT work inside tables)

' --------------------------------------------------------------------------------
' Copyright ©2010 Zebra on Wheels, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.

' Check that selection type is text
If ActiveWindow.Selection.Type = ppSelectionText Then

' Count lines selected
With ActiveWindow.Selection.TextRange
SelectedParagraphs = .Characters(Start:=.Start, Length:=.Length).Paragraphs.Count
End With

' Check that only one paragraph is selected
If SelectedParagraphs < 2 Then

' ########################################################################### ##
' This is where the "magic" begins
' ########################################################################### ##

' Retrieve the cursor position in number of characters from the beginning of the text inside the text box
CurrentCursorPositionInCharacters = ActiveWindow.Selection.TextRange.Start

' Select the all the text in the shape from the beginning until the currentcursor position
' and count the paragraphs in the selection
With ActiveWindow.Selection.ShapeRange.TextFrame
ParagraphNumber = .TextRange.Characters(Start:=0, Length:=CurrentCursorPositionInCharacters).Paragraphs.Count
End With

MsgBox "Cursor is on paragraph Number: " & ParagraphNumber

' ########################################################################### ##
' "Magic" ends - simple, no?
' ########################################################################### ##
Else
MsgBox "You have selected " & SelectedParagraphs & " paragraphs." & vbCrLf & vbCrLf & _
"Please do not select text spanning more than one paragraph" & vbCrLf & vbCrLf & _
"and try again."
End If
Else
MsgBox "Please place the cursor inside a text box and try again"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top