vba problem with tables?

G

Geoff Cox

Hello,

the following code replaces the word "fred" by "jim" in all slides and
works fine in most cases but appears to fail when there is a table?

How could I keep the tables and still have the macro run?

Thanks

Geoff


Dim oSld As Slide
Dim oShp As Shape
Dim oTxtRng As TextRange
Dim oTmpRng As TextRange
Dim slide_number As Integer

For slide_number = 1 To ActivePresentation.Slides.Count

Set oSld = Application.ActivePresentation.Slides(slide_number)

For Each oShp In oSld.Shapes
Set oTxtRng = oShp.TextFrame.TextRange
Set oTmpRng = oTxtRng.Replace(FindWhat:="fred", _
Replacewhat:="jim", WholeWords:=True)
Do While Not oTmpRng Is Nothing
Set oTxtRng = oTxtRng.Characters(oTmpRng.Start +
oTmpRng.Length, _
oTxtRng.Length)
Set oTmpRng = oTxtRng.Replace(FindWhat:="fred", _
Replacewhat:="jim", WholeWords:=True)
Loop
Next oShp

Next slide_number
 
G

Geoff Cox

Hello,

the following code replaces the word "fred" by "jim" in all slides and
works fine in most cases but appears to fail when there is a table?

How could I keep the tables and still have the macro run?

I should have added that the error message (with a table present) is

"TextFrame (unknown member): Invalid request. This type of shape
cannot have a TextRange."

and debug highlights

set oTxtRng = oShp.TextFrame.TextRange

Cheers

Geoff
 
G

Geoff Cox

On Thu, 27 Apr 2006 09:01:27 +0100, Geoff Cox

Seem to have found the answer!

The next code due to Steve (Rindsberg) I think...

If oShp.HasTextFrame Then
On Error Resume Next
If oShp.TextFrame.HasText Then

etc etc

End If
End If
' reset error trap
On Error GoTo 0 ' or on error goto YourErrorHandler

Asking for help often seems to push me to look/think again!

Geoff


Dim oSld As Slide
Dim oShp As Shape
Dim oTxtRng As TextRange
Dim oTmpRng As TextRange
Dim slide_number As Integer

For slide_number = 1 To ActivePresentation.Slides.Count

Set oSld = Application.ActivePresentation.Slides(slide_number)

For Each oShp In oSld.Shapes

If oShp.HasTextFrame Then
On Error Resume Next
If oShp.TextFrame.HasText Then

Set oTxtRng = oShp.TextFrame.TextRange
Set oTmpRng = oTxtRng.Replace(FindWhat:="achievement", _
Replacewhat:="teaching", WholeWords:=True)
Do While Not oTmpRng Is Nothing
Set oTxtRng = oTxtRng.Characters(oTmpRng.Start +
oTmpRng.Length, _
oTxtRng.Length)
Set oTmpRng = oTxtRng.Replace(FindWhat:="achievement", _
Replacewhat:="teaching", WholeWords:=True)
Loop

End If
End If
' reset error trap
On Error GoTo 0 ' or on error goto YourErrorHandler

Next oShp

Next slide_number

End With

oPresentation.Save
oPresentation.Close



End Sub
 

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