Need VBA Code for Searching & Replacing within Grouped Objects

  • Thread starter Thread starter Cathy
  • Start date Start date
C

Cathy

I have a PowerPoint macro that searches and replaces a lot of terminology
within a presentation to make it company compliant. The macro works fine on
text slides and objects that have text in them that are not grouped,
however, it cannot enter the grouped objects and replace text where
necessary.

If anyone knows how to write this in VBA, I would be very grateful to hear
from them. I am using PowerPoint 2002.

Thank you.
 
I'm not sure, but I think you will have to ungroup the objects first with something like

ActivePresentation.Slides(1).Shapes("Group 6").Ungrou
MsgBox "This is where you can play with the text
With ActivePresentation.Slides(1).Shapes.Range().Regrou

If the shapes don't need to end up grouped, you can skip the last line. Keep in mind that Regroup will regroup the last set of ungrouped objects, so you can't do a bunch of ungroups and then regroup and expect it to work

I hope this helps

--Davi

David M. Marcovit
Author of _Powerful PowerPoint for Educators
http://www.loyola.edu/education/PowerfulPowerPoint

----- Cathy wrote: ----

I have a PowerPoint macro that searches and replaces a lot of terminolog
within a presentation to make it company compliant. The macro works fine o
text slides and objects that have text in them that are not grouped
however, it cannot enter the grouped objects and replace text wher
necessary

If anyone knows how to write this in VBA, I would be very grateful to hea
from them. I am using PowerPoint 2002

Thank you.
 
I have a PowerPoint macro that searches and replaces a lot of terminology
within a presentation to make it company compliant. The macro works fine on
text slides and objects that have text in them that are not grouped,
however, it cannot enter the grouped objects and replace text where
necessary.

If anyone knows how to write this in VBA, I would be very grateful to hear
from them. I am using PowerPoint 2002.

You'd probably want to do this as a Select Case on .Type, but this illustrates
what you need to do:

Sub ReplaceTextInGroup()

Dim X As Long
With ActiveWindow.Selection.ShapeRange
If .Type = msoGroup Then
For X = 1 To .GroupItems.Count
If .GroupItems(X).HasTextFrame Then
If .GroupItems(X).TextFrame.HasText Then
' Obviously, you'd run your own replace code here:
.GroupItems(X).TextFrame.TextRange.Text = "HA! Gotcha!"
End If
End If
Next X
End If
End With

End Sub


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
David M. said:
Cool. I didn't know you could do that.

It's not real intuitive. <g>

And it gets ugly if you decide you want to handle groups within groups within
... yeah, well. You get the idea.


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
It's not real intuitive. <g>

And it gets ugly if you decide you want to handle groups within groups
within .. yeah, well. You get the idea.

It's particularly tough finding things like this on the Mac version where
you can't just press . and have all the options pop up. Scouring the
help files is much harder.

--David
--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
Steve,

Thank you so much for responding to my request for help. I think what you
wrote will help us a lot. The way my macro is laid out is quite involved,
so we won't be able to do it exactly the way you have it written, but will
should be able to use most of it. Again, I can't thank you enough.

Cathy
 
Hi David,

Thank you for your help. I think the way that Steve wrote this out is what
we will try to use, so we don't have to ungroup and regroup everything.
Again, thank you for taking the time to respond.

Cathy
 
It's particularly tough finding things like this on the Mac version where
you can't just press . and have all the options pop up. Scouring the
help files is much harder.

My theory is that if you want to develop on the Mac, the only sane way to do it
is to buy VPC, Windows and Office. Costs more to get started, but saves a
bundle in time down the line. Or just set a Mac and a PC up on the same
network. <g>



--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
Steve,

Thank you so much for responding to my request for help. I think what you
wrote will help us a lot. The way my macro is laid out is quite involved,
so we won't be able to do it exactly the way you have it written,

No, I wouldn't expect so. That was about as generic an example as I could cook
up on short notice. I figured if you'd gotten far enough to need an answer to
that question, you were way past smart enough to apply this example to what
you're doing. <g>


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
Just as a head's up, using this method would cause the loss of any
animations attached to the group.


David M. Marcovitz said:
I'm not sure, but I think you will have to ungroup the objects first with something like:

ActivePresentation.Slides(1).Shapes("Group 6").Ungroup
MsgBox "This is where you can play with the text"
With ActivePresentation.Slides(1).Shapes.Range().Regroup

If the shapes don't need to end up grouped, you can skip the last line.
Keep in mind that Regroup will regroup the last set of ungrouped objects, so
you can't do a bunch of ungroups and then regroup and expect it to work.
 
It's not real intuitive. <g>

Nor is Steve, which is why, most of the time, he is so good. Other
times, I just gotta think he's being intuitive, or just lost his mind.
Your guess?

Brian Reilly, PowerPoint MVP

who doesn't actually have a mind to lose. Told by a friend of my wife
a long time ago, that it'd be a terrible thing to lose, but didn't
listen to either of them. Should have.
 
Hi Shyam,

Thank you so much for responding to this message. The code on your site was
really helpful. Following what you had, we were able to get our macro to
work within groups. You were right about it getting messy when you need to
handle groups within groups, because that's what we ended up having to do.

This was my first time posting a question on this site and everyone was
extremely helpful and responsive. Thank you again!!

Cathy
Shyam Pillai said:
And it gets ugly if you decide you want to handle groups within groups
within
http://www.mvps.org/skp/ppt00025.htm#2 : )

Regards
Shyam


 
Back
Top