Re: Using VBA to replace text
- From: Steve Rindsberg <abuse@xxxxxxxxxxxxx>
- Date: Mon, 04 Apr 2005 17:47:48 EDT
In article <3be051l6t3h1viufptivns16uof6mu6h6n@xxxxxxx>, Jeff Jones wrote:
> I'm having an opportuniy meeting an objective. I have a character
> string that I need to replace in many presesnations. I, frankly,
> don't want to do this manually. It would be easy if PowerPoint
> actually allowed me to record the key strokes to do a "replace all"
> but it doesn't. I've created the following subroutine. The problem
> is complicated by the fact that the text is on the Slidemaster. The
> code below selects the first slide. The code doesn't get a hit on the
> search string because it's on the slidemaster.
>
> I can activate the slidemaster by including ActiveWindow.ViewType =
> ppViewTitleMaster but haven't been able to figure out how to set the
> oSld variable to the master. I get a type mismatch. Can anyone help
> me to set the slide variable so I can spin through the shapes until
> I've gotten to the one with the text I want to change. Any
> alternative would do. Once I get this code working I can wrap in the
> code to process all the slides in a selected folder.
>
You can get around this by using:
Dim oSld as Object ' instead of Slide
You could then:
' Do the slides
For each oSld in ActivePresentation.Slides
call FixUp(oSld)
Next ' slide
' Do the Slide and Title masters
Set oSld = ActivePresentation.SlideMaster
call Fixup(oSld)
If ActivePresentation.HasTitleMaster Then
Set oSld = ActivePresentation.TitleMaster
call FixUp(oSld)
End if
Sub FixUp (oSld as Object)
' here's where you pop in the code you're already using for the
' search/replace
Dim oSh as Shape
For each oSh in oSld.Shapes
' do yer stuff
Next
End Sub
As David's mentioned, it gets a bit more complex if you have multiple masters,
but this is a start.
> Sub Change_Text()
>
> Dim oSld As Slide
> Dim oShp As Shape
> Dim oTxtRng As TextRange
> Dim oTmpRng As TextRange
>
> Set oSld = Application.ActivePresentation.Slides(1)
> On Error Resume Next
>
> For Each oShp In oSld.Shapes
> Set oTxtRng = oShp.TextFrame.TextRange
> Set oTmpRng = oTxtRng.Replace(FindWhat:="original text.", _
> Replacewhat:="replacement text", WholeWords:=True)
> Do While Not oTmpRng Is Nothing
> Set oTxtRng = oTxtRng.Characters(oTmpRng.Start +
> oTmpRng.Length, _
> oTxtRng.Length)
> Set oTmpRng = oTxtRng.Replace(FindWhat:="original text", _
> Replacewhat:="replacement text", WholeWords:=True)
> Loop
> Next oShp
>
> End Sub
>
> I'd sure appreciate any suggestions that anyone may have.
>
> Thank you,
> Jeff
>
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
.
- Follow-Ups:
- Re: Using VBA to replace text
- From: Jeff Jones
- Re: Using VBA to replace text
- References:
- Using VBA to replace text
- From: Jeff Jones
- Using VBA to replace text
- Prev by Date: Re: How do I save just the presentation & not PP software to send
- Next by Date: Re: Embedded PDF
- Previous by thread: Re: Using VBA to replace text
- Next by thread: Re: Using VBA to replace text
- Index(es):
Relevant Pages
|
Loading