Rosenrot
03-16-2017, 08:16 AM
Hi everyone,
I’m working on the macro the aim of which is to search for certain words (Note; Source) within the text boxes. In other words, the macro should change the dimension of text boxes containing these particular words in the following way:
.Width = 773
.Height = 24
.Left = 15
.Top = 520
I have already created the macro but I noticed it crashes VBA and the entire PowerPoint every time I run it. As a result, I cannot even find out whether the code is properly written.
Do you have any ideas how to fix this problem or how to modify the code, so that it does not harm PowerPoint?
The code is as follows:
Sub NoteandSource()
Dim oSld As Slide
Dim oShp As Shape
Dim TR As TextRange
Dim TRFind1 As TextRange
Dim TRFind2 As TextRange
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
Set TR = oShp.TextFrame.TextRange
Set TRFind1 = TR.Find(FindWhat:="Note")
Set TRFind2 = TR.Find(FindWhat:="Source")
Do While Not (TRFind1 Is Nothing)
Do While Not (TRFind2 Is Nothing)
With oShp
.Width = 773
.Height = 24
.Left = 15
.Top = 520
End With
Loop
Loop
End If
End If
Next
Next
End Sub
I’m working on the macro the aim of which is to search for certain words (Note; Source) within the text boxes. In other words, the macro should change the dimension of text boxes containing these particular words in the following way:
.Width = 773
.Height = 24
.Left = 15
.Top = 520
I have already created the macro but I noticed it crashes VBA and the entire PowerPoint every time I run it. As a result, I cannot even find out whether the code is properly written.
Do you have any ideas how to fix this problem or how to modify the code, so that it does not harm PowerPoint?
The code is as follows:
Sub NoteandSource()
Dim oSld As Slide
Dim oShp As Shape
Dim TR As TextRange
Dim TRFind1 As TextRange
Dim TRFind2 As TextRange
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
Set TR = oShp.TextFrame.TextRange
Set TRFind1 = TR.Find(FindWhat:="Note")
Set TRFind2 = TR.Find(FindWhat:="Source")
Do While Not (TRFind1 Is Nothing)
Do While Not (TRFind2 Is Nothing)
With oShp
.Width = 773
.Height = 24
.Left = 15
.Top = 520
End With
Loop
Loop
End If
End If
Next
Next
End Sub