Finding text via macro in Powerpoint

D

dominik.hartung

Hello everybody,

I´m searching for a macro to
1) look for some text in the notes page of each slide in a
presentation
2) take that slide and move it to a certain position.

I already manged to get some code information, here it is:

Sub sort()
Dim pos, search As Integer
search = InputBox("Find:")
pos = InputBox("Move to position:")

For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes.NotesPage
If shp.HasText Then
Set txtRng = shp.Text.TextRange
Set foundText = txtRng.Find(FindWhat:=search)
Do While Not (foundText Is Nothing)
ActiveSlide.MoveTo toPos:=pos
Loop
End If
Next
Next

End Sub

This is basically from the help in Powerpoint (example of the find
function), but I just can´t get that macro to work. I would be very
grateful if anyone could help me out.

Thanks a lot in advance
Dominik
 
D

David M. Marcovitz

I'm not entirely sure what you're trying to do, but you might want to go
to the Debug menu and choose Compile VBA Project to find out some of your
errors before you try to run the macro. You have several errors. The most
serious seems to be the odd loop that you have. If it did work, it would
probably hang PowerPoint because there is nothing to change the condition
to False so it will stop looping. I'm not sure why you want a loop there
at all. I have cleaned up your code, but it still has (at least) one
flaw:

Sub sort()
Dim pos As Integer
Dim search As Integer
Dim shp As Shape
Dim sld As Slide
search = InputBox("Find:")
pos = InputBox("Move to position:")

For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.NotesPage.Shapes
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
Set foundtext = txtRng.Find(FindWhat:=search)
If Not (foundtext Is Nothing) Then
sld.MoveTo toPos:=pos
End If
End If
Next
Next

End Sub


The flaw is that you are searching through all the slides. If you really
only want to move one slide, and you are sure that is the only one that
will meet your condition, this will work. However, if you want to move
several slides, looping through the slides in this way will not work
because once you have moved a slide, your "For each sld" loop will not
work well.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

(e-mail address removed) wrote in @p47g2000hsd.googlegroups.com:
 
D

dominik.hartung

Hi David and thanks for your answer,

the point is that I got about 200 slides each with an individual code
inside the notes.
The first line of the notes field says something like:

"ProtocoID: 2145"

The slides are somehow mxied up and to get that sorted by ID, I´m
trying to write that marco.
Additionally, there will be more than those 200 slides to come and I
really want to avoid doing it manually.

So, all IDs are unique and the macro has to search for every ID inside
the whole presentation, so the loop is fine (that would be the
"answer" to your question. I´m trying to improve the code, but
honestly not very successful.

Maybe there´s still another way I haven´t figured out...what do you
think?

Dominik
 
D

David M. Marcovitz

OK. So what you have is something that takes 1 slide and puts it at one
location. It seems to me that you what you have designed is no better (or
perhaps slightly better) than doing it manually (unless you have really
complex sorting requirements that cannot be coded (that is, only you know
that 2415 means stick this at location 3, so you have to type each
location manually). There are a lot of sorting algorithms, but with only
a couple of hundred slides, it shouldn't matter if you use an inefficient
sort because any reasonably fast computer should zip through it quickly.

This shouldn't be too hard to write, but I don't have the time to write
it for you now. Look up sorting algorithm on the web, and I'm sure you'll
find a bunch of algorithms that can easily be put into VBA and used to
sort slides based on any criteria you want.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

(e-mail address removed) wrote in
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top