The specified value is out of range - vba

I am trying to write some code that returns in the Immediate Window the slide number of every slide that contains at least one Text Box with a red font, but the following error keeps popping up. Do you have ideas on how I can solve the problem?
Below the error I get:
Run-time error'-2147024809(80070057)
The specified value is out of range.
The line that causes it is:
ElseIf shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
This is the full code of the Subroutine:
Sub redfont()
Dim sld As Slide
Dim shp As Shape
Dim x As Byte
Dim z, i
With ActivePresentation
z = .Slides(.Slides.Count).SlideNumber
MsgBox z, vbDefaultButton1, "Total Slides"
End With
Dim myCol As Collection
Set myCol = New Collection
For i = 2 To z
Set sld = ActivePresentation.Slides(i)
For Each shp In sld.Shapes
If x = 1 Then
x = 1
ElseIf shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
myCol.Add CStr(i), CStr(i)
x = 1
End If
Next shp
x = 0
Next
Dim j As Long
For j = 1 To myCol.Count
Debug.Print myCol.Item(j)
Next j
End Sub

Since not all Shapes have a TextFrame, you need to check first whether your shape has one or not before trying to access it.
Use the .HasTextFrame property for that purpose.
The general pattern is:
If shp.HasTextFrame Then
'Access shp.TextFrame inside here
'For example:
shp.TextFrame.TextRange.Text = "New Text"
End If
In your specific case the correct code would look like this:
For i = 2 To z
Set sld = ActivePresentation.Slides(i)
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Then
myCol.Add CStr(i), CStr(i)
Exit For
End If
End If
Next
Next
BTW: you don't need the x variable, just exit the loop when the first condition is met.

Related

Find some shapes by name, other shapes by specific color and delete them

I have a few presentations with shapes I need to delete, with
specific .Name
specific color
Those shapes with specific .Name can be grouped (not in my code). I found code in stackoverflow and tried to modify it.
Find shape by name and delete it: Specific .Name can be "XXName1" as well "Name1".
If there are no shapes with .Name = "Name1" I get an Error
"Object does not exist"
on the line If .Name = "Name1" Or .Name = "Name2" Then
Sometimes the code works, and then, if there are a lot slides in the presentation, I have an error.
When I test with a 1-slide presentation - no error.
Find shape by color and delete it:
I have an Error
"Object variable or With block variable not set"
I don't understand how to declare variable
Sub DeleteShapes()
Dim oSld As Slide
Dim oShp As Shape
Dim oshpGroup As Shape
Dim Y As Long
Dim L As Long
Dim str As String
For Each oSld In ActivePresentation.Slides
For L = oSld.Shapes.Count To 1 Step -1
With oSld.Shapes(L)
' Find shape by name and delete it
If .Name = "XXName1" Or .Name = "XXName2" Then
.Delete
End If
If .Name = "Name1" Or .Name = "Name2" Then
.Delete
End If
' Find shape by color and delete it
If oShp.Fill.ForeColor.RGB = RGB(0, 0, 0) Or _
oShp.Fill.ForeColor.RGB = RGB(1, 1, 1) Or _
oShp.Fill.ForeColor.RGB = RGB(2, 2, 2) Or _
oShp.Fill.ForeColor.RGB = RGB(3, 3, 3) Then
oShp.Delete
End If
End With
Next L
Next oSld
End Sub
You can't refer to a shape after you've deleted it (which you've done
previously). Change your sequential If...End If, If...End If to
If...ElseIf....ElseIf...End If. – #BigBen
My revised code:
Sub DeleteShapes()
Dim oSld As Slide
Dim oShp As Shape
Dim L As Long
For Each oSld In ActivePresentation.Slides
For L = oSld.Shapes.Count To 1 Step -1
With oSld.Shapes(L)
If .Name = "XXName1" Or .Name = "XXName2" Then
.Delete
ElseIf .Name = "Name1" Or .Name = "Name2" Then
.Delete
ElseIf .Fill.ForeColor.RGB = RGB(0, 0, 0) Then
.Delete
ElseIf .Fill.ForeColor.RGB = RGB(1, 1, 1) Then
.Delete
ElseIf .Fill.ForeColor.RGB = RGB(2, 2, 2) Then
.Delete
ElseIf .Fill.ForeColor.RGB = RGB(3, 3, 3) Then
.Delete
End If
End With
Next L
Next oSld
End Sub

Reverse engineer the VBA code you need to produce graphs in a slide

I am looking for a way to kind of re-engineer the VBA code I need to create a certain visual in PowerPoint.
For example purposes let's say, I want to create code to create this:
Right now I have wrote the following VBA code that allows you highlight the shapes used in the powerpoint:
Sub ListAllShapes()
Dim curSlide As Slide
Dim curShape As Shape
For Each curSlide In ActivePresentation.Slides
Debug.Print curSlide.SlideNumber
For Each curShape In curSlide.Shapes
MsgBox curShape.Name
Next curShape
Next curSlide
End Sub
If I run this with my example I get the following output:
Autoshape 7
However when I then lookup the Shape.name here: https://learn.microsoft.com/en-us/office/vba/api/office.msoautoshapetype I see that Autoshpape 7 is msoShapeIsoscelesTriangle. If I then insert the following code:
Sub InsertShape()
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddShape Type:=msoShapeIsoscelesTriangle, _
Left:=50, Top:=50, Width:=100, Height:=200
End Sub
I get a different graph, any thoughts on where I am going wrong?
The autoshape Name is not the autoshape Type. They're 2 different properties. Here's a macro to add all the shapes to a slide. Then look up the number on this page to get the VBA AutoshapeType name: MsoAutoShapeType enumeration
Sub MakeShapes()
Dim T As Long, L As Long
Dim oShape As Shape, oText As Shape
T = 0
L = 0
x = 1
For y = 1 To 15
For Z = 1 To 26
On Error GoTo NoShape
Set oShape = ActiveWindow.Selection.SlideRange.Shapes.AddShape(Type:=x, Left:=L, Top:=T, Width:=30, Height:=30)
On Error GoTo -1
Set oText = ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=L, Top:=T + 36, Width:=36, Height:=18)
With oText.TextFrame2.TextRange
.Text = oShape.AutoShapeType
.Font.Size = 10
End With
Set oShape = Nothing
Set oText = Nothing
L = L + 36
NoShape:
x = x + 1
If x = 184 Then Exit Sub
Next Z
L = 0
T = T + 71
Next y
End Sub

How to group each shape in a selection of a PowerPoint slide using VBA?

I am working on a landscape diagram that has many shapes. I am trying to do following in a slide that has many shapes by selecting all the shapes at once (Ctrl + A) and perform grouping. If I do this manually by selecting the inbuilt group function present in PowerPoint, the shapes (red and yellow boxes) are not grouped, instead all four boxes are grouped as bunch.
I am trying to achieve the following: (Taking reference of example attached)
Select all 4 shapes
when macro is run, the boxes should be grouped (i.e yellow and red shapes should be paired as well as green and blue shapes)
Following is the code I tried for achieving this. But, only first two shapes in the selection were grouped where as other two are not.
Sub Grouping2()
Dim V As Long
Dim oSh1 As Shape
Dim oSh2 As Shape
Dim Shapesarray() As Shape
Dim oGroup As Shape
Dim oSl As Slide
Call rename
On Error Resume Next
If ActiveWindow.Selection.ShapeRange.Count < 2 Then
MsgBox "Select at least 2 shapes"
Exit Sub
End If
ReDim Shapesarray(1 To ActiveWindow.Selection.ShapeRange.Count)
For V = 1 To ActiveWindow.Selection.ShapeRange.Count
Set oSh1 = ActiveWindow.Selection.ShapeRange(V)
Set oSh2 = ActiveWindow.Selection.ShapeRange(V + 1)
If ShapesOverlap(oSh1, oSh2) = True Then
Set Shapesarray(V) = oSh1
Set Shapesarray(V + 1) = oSh2
' group items in array
ActivePresentation.Slides(1).Shapes.Range(Array(oSh1.Name, oSh2.Name)).Group
'else move to next shape in selction range and check
End If
V = V + 1
Next V
End Sub
Sub rename()
Dim osld As Slide
Dim oshp As Shape
Dim L As Long
Set osld = ActiveWindow.Selection.SlideRange(1)
For Each oshp In osld.Shapes
If Not oshp.Type = msoPlaceholder Then
L = L + 1
oshp.Name = "myShape" & CStr(L)
End If
Next oshp
End Sub
In the first loop iteration, when the first two shapes are grouped, all of the shapes get de-selected. And so in your subsequent loop, you would have received an error, but since you enabled error handling with On Error Resume Next without disabling it afterwards, the error is hidden.
Error Handling After you've enabled error handling and tested whether more than one shape has been selected, you should disable it. Should you need it at some point, it can be enabled again.
On Error Resume Next
If ActiveWindow.Selection.ShapeRange.Count < 2 Then
MsgBox "Select at least 2 shapes"
Exit Sub
End If
On Error GoTo 0
Array Assignment Assign each of the selected shapes to an element within the array.
Dim Shapesarray() As Shape
ReDim Shapesarray(1 To ActiveWindow.Selection.ShapeRange.Count)
Dim V As Long
For V = 1 To ActiveWindow.Selection.ShapeRange.Count
Set Shapesarray(V) = ActiveWindow.Selection.ShapeRange(V)
Next V
Grouping Loop through the array, test whether the shapes within each pair overlap, and then make sure that neither are already part of a group.
For V = LBound(Shapesarray) To UBound(Shapesarray) - 1
If ShapesOverlap(Shapesarray(V), Shapesarray(V + 1)) Then
If Not Shapesarray(V).Child And Not Shapesarray(V + 1).Child Then
ActiveWindow.View.Slide.Shapes.Range(Array(Shapesarray(V).Name, Shapesarray(V + 1).Name)).Group
End If
End If
Next V
The complete code would be as follows...
Sub Grouping2()
'Call rename
On Error Resume Next
If ActiveWindow.Selection.ShapeRange.Count < 2 Then
MsgBox "Select at least 2 shapes"
Exit Sub
End If
On Error GoTo 0
Dim Shapesarray() As Shape
ReDim Shapesarray(1 To ActiveWindow.Selection.ShapeRange.Count)
Dim V As Long
For V = 1 To ActiveWindow.Selection.ShapeRange.Count
Set Shapesarray(V) = ActiveWindow.Selection.ShapeRange(V)
Next V
For V = LBound(Shapesarray) To UBound(Shapesarray) - 1
If ShapesOverlap(Shapesarray(V), Shapesarray(V + 1)) Then
If Not Shapesarray(V).Child And Not Shapesarray(V + 1).Child Then
ActiveWindow.View.Slide.Shapes.Range(Array(Shapesarray(V).Name, Shapesarray(V + 1).Name)).Group
End If
End If
Next V
End Sub

Powerpoint & VBA New slide if table bottom exceeds the bottom of the slide

So i have been struggling with this for the past few days, i have this powerpoint 2007 presentation that i fill with information from a button in a from in a access file using VBA.
And in the first slide (and only by now) i have a table that will receive part of the information, however i can't make the table content break to another slide if the table exceeds the bottom of the slide, it just goes out of range.
I have the method to create a the new slide, and that works fine. But i can't seem to find an example that could get me started.
I think i should be something like check the table bottom exceeds slide bottom if it does create a new slide, cut the overlap cells and paste them in the new slide?
Thanks in Advance.
The code example:
' Open PowerPoint
Dim pptobj As PowerPoint.Application
Dim Presentation As PowerPoint.Presentation
Dim oSl as Slide
Set pptobj = New PowerPoint.Application
Set pptobj = CreateObject("Powerpoint.Application")
pptobj.Activate
Set Presentation = pptobj.Presentations.Open("C:\Users\some.pptx")
pptobj.Visible = True
pptobj.WindowState = ppWindowMaximized
If ((Len(Forms!Some!Name> 0) Then
pptobj.ActivePresentation.Slides(1).Shapes("TableNome").Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!Name))
End If
Set oSl = pptobj.ActivePresentation.Slides(1)
With oSl
.Shapes("TableCategory").Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = (CStr(Forms!CVLong!TxtCategory))
.Shapes("TableEmail").Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!TxtEmail))
.Shapes("TableData").Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!TxtTlf))
.Shapes("TableData").Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!TxtCell))
End With
Dim oSh as Shape
Dim overhang
Set oSh = pptobj.ActivePresentation.Slides(1).Shapes.AddTable(1, 3, 50, 100, 493)
'One
If ((Len(Forms!Some!One)) > 0) Then
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!One)) & vbNewLine & vbNewLine
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "One"
End If
'Two
If (Len(Forms!Some!Two> 0) Then
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(5, 3).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!Two)) & vbNewLine
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(5, 1).Shape.TextFrame.TextRange.Text = "Two"
End If
'Three
If (Len(Forms!Some!Three) > 0) Then
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(4, 3).Shape.TextFrame.TextRange.Text = (CStr(Forms!Some!Three)) & vbNewLine & vbNewLine
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(4, 1).Shape.TextFrame.TextRange.Text = "Three"
End If
'Add Slide
Dim Sld As Slide
Dim x As Integer
x = 1
Set Sld = pptobj.ActivePresentation.Slides.Add(Index:=pptobj.ActivePresentation.Slides.Count + 1, Layout:=ppLayoutBlank)
For Each Sld In pptobj.ActivePresentation.Slides
If x >= 2 Then
pptobj.ActivePresentation.Slides(1).Shapes("Text Placeholder 15").Copy
pptobj.ActivePresentation.Slides(x).Shapes.Paste
pptobj.ActivePresentation.Slides(x).Shapes("Text Placeholder 15").ZOrder msoSendToBack
pptobj.ActivePresentation.Slides(x).Shapes("Text Placeholder 15").Height = 810
pptobj.ActivePresentation.Slides(x).Shapes("Text Placeholder 15").Top = 19
End If
x = x + 1
Next
End If
'Put table top border
Dim n As Integer
Dim r As Integer
n = 3
r = 1
While r <= n
If Len(pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(r, 3).Shape.TextFrame.TextRange.Text) > 0 Then
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(r, 3).Borders(ppBorderTop).Visible = msoTrue
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Cell(r, 3).Borders(ppBorderTop).ForeColor.RGB = RGB(220, 105, 0)
Else
pptobj.ActivePresentation.Slides(1).Shapes("TableInfo").Table.Rows(r).Delete
n = n - 1
r = r - 1
End If
r = r + 1
Wend
'Add Photo
pptobj.ActivePresentation.Slides(1).Shapes.AddPicture(FileName:="\\someplace\" & [Id] & ".jpg", linktofile:=mostrue, savewithdocument:=msoTrue, Left:=52, Top:=115).Select
With pptobj.ActivePresentation.Slides(1).Shapes("Picture 7")
.LockAspectRatio = msoTrue
.Width = 85
.Left = 38
.Top = 80
End With
'add footer
Dim page As Integer
page = 1
Dim s As Slide
For Each s In pptobj.ActivePresentation.Slides
On Error Resume Next
Set oSh = s.HeadersFooters.Footer
If Err.Number <> 0 Then
Call s.Master.Shapes.AddPlaceholder(ppPlaceholderFooter, 219, 805, 342, 19)
End If
On Error GoTo 0
s.HeadersFooters.Footer.Visible = msoTrue
s.HeadersFooters.Footer.Text = (CStr(Forms!Some!Name)) & " - Page " & page & " of " & pptobj.ActivePresentation.Slides.Count
page = page + 1
Next
The following code snippet may give you some inspiration. Right now it just determines that the table is too large and gives you a message. Without more information about the type of data and how you obtained it, it's hard to give an answer to the second part of the problem. Most likely you would create a table, add one row at a time and check the size of the table; when the table gets too large (or within a certain distance from the bottom) you create a new slide and continue the process. That is probably better than creating a table that's too large, then trying to figure out where to cut it.
Here is the code:
Sub createTable()
Dim oSl As Slide
Dim oSh As Shape
Dim overhang
Set oSl = ActivePresentation.Slides(1)
Set oSh = oSl.Shapes.AddTable(28, 3)
overhang = ActivePresentation.PageSetup.SlideHeight - (oSh.Height + oSh.Top)
If overhang > 0 Then
MsgBox "the table fits"
Else
MsgBox "the table is too big!"
End If
End Sub

Copying animation and sequence information between powerpoint shapes

I'm trying to replace all shape objects on the slide (pictures) with shape objects of another type (rectangular shape). I can delete old object and create new, but i will loose all animation information and sequence order. Is it possible to store animation information and order in timeline, and copy it to the new shape object?
Well, i have found a solution myself, hope someone could find it useful. So, it is not necessary to copy animation information from old shape to a new one, just cycle through sequence's items and replace the shape object refrence to the new shape. Like this:
On Error Resume Next
Dim shp1 As Shape 'old shape
Set shp1 = ActivePresentation.Slides(1).Shapes(3)
Dim shp2 As Shape 'new shape
Set shp2 = ActivePresentation.Slides(1).Shapes.AddPicture("c:\imgres2.jpg", msoFalse, msoTrue, 0, 0) 'it is important to create new shape before cycling through existing ones.
For i = ActivePresentation.Slides(1).TimeLine.MainSequence.count To 1 Step -1
'using "is" opeartor to compare refrences
If shp1 Is ActivePresentation.Slides(1).TimeLine.MainSequence.Item(i).Shape Then
ActivePresentation.Slides(1).TimeLine.MainSequence.Item(i).Shape = shp2
End If
Next i
shp1.Delete 'delete the old shape
Try something like this code to copy the animation into new added shape:
Sub PasteAnimationBehaviours()
Dim SHP As Shape 'for existing shape
Set SHP = ActivePresentation.Slides(1).Shapes(1)
SHP.PickupAnimation
Dim newSHP As Shape 'pasting to new shape
Set newSHP = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeRectangle, 100, 100, 100, 100)
newSHP.ApplyAnimation
End Sub
Added after comment: If you only need to replace type of shape try to use something like this:
Sub ShapeSubstition()
Dim SHP As Shape 'for existing shape
'test for 1st shape in 1st slide
Set SHP = ActivePresentation.Slides(1).Shapes(1)
SHP.AutoShapeType = msoShapeRectangle 'to rectangle
SHP.AutoShapeType = msoShapeOval 'to oval
End Sub
I think it is probably easier to just use the "Animation Painter" command button to copy the animations and apply them to another object. The Animation Painter functions in the same way as the Format Painter. After you have copied the desired animations, you can reorder the individual animations using the Animation Pane.
This code shows how to copy effects from one shape to another. Select a shape before running routine "SetSourceShape" and select one or more shapes before running "PaintEffects".
Option Explicit
' resources:
' http://msdn.microsoft.com/en-us/library/aa168134(v=office.11).aspx
' http://msdn.microsoft.com/en-us/library/aa168135(office.11).aspx
' http://skp.mvps.org/ppttimeline1.htm
' uses functions from:
' https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-copy-paste-animation-effect-in-powerpoint/c0f255c0-167a-4a12-ae37-1e713ee1d8df
Public MySourceShapeId As Long
Public MySourceSlideIndex As Long ' need this with shape id for unique selection
Sub SetSourceShape() ' sets source shape id value if successfull
Dim oShp As PowerPoint.Shape
Dim myShp As PowerPoint.Shape
Dim oSld As Slide
Dim oEffect As Effect
Dim HowMany As Long
Dim FoundEffect As Boolean
HowMany = 0 ' default value for nothing selected
MySourceShapeId = 0 ' default value for nothing available to copy
MySourceSlideIndex = 0
FoundEffect = False ' default value unless selected shape has any effect(s)
On Error Resume Next ' handles error when nothing is selected
HowMany = ActiveWindow.Selection.ShapeRange.Count
On Error GoTo 0 ' restore normal error handling
If HowMany = 0 Then
MsgBox "Nothing is selected"
Else
If HowMany = 1 Then
Set oShp = ActiveWindow.Selection.ShapeRange(1) ' selection on a single slide
For Each oEffect In ActiveWindow.Selection.SlideRange(1).TimeLine.MainSequence
If oEffect.Shape.Id = oShp.Id Then
MySourceShapeId = oShp.Id
MySourceSlideIndex = ActiveWindow.Selection.SlideRange(1).SlideIndex
FoundEffect = True
End If
Next
If FoundEffect Then
MsgBox "Source is selected, Slide: " & MySourceSlideIndex & ", ShapeID: " & MySourceShapeId
Else
MsgBox "Selected item has no effect(s)"
End If
Else
MsgBox "Select only one item"
End If
End If
End Sub
Sub PaintEffects()
Dim oShp As PowerPoint.Shape
Dim oEffect As Effect
Dim HowMany As Long
Dim msg As String
HowMany = 0 ' default value for nothing selected
If MySourceShapeId = 0 Then
MsgBox "No source is selected"
Exit Sub
End If
On Error Resume Next ' handles error when nothing is selected
HowMany = ActiveWindow.Selection.ShapeRange.Count
On Error GoTo 0 ' restore normal error handling
If HowMany = 0 Then
MsgBox "Nothing is selected to paint"
Else
' make sure source is not in this selection
If ActiveWindow.Selection.SlideRange(1).SlideIndex = MySourceSlideIndex Then ' check shapes
For Each oShp In ActiveWindow.Selection.ShapeRange
If oShp.Id = MySourceShapeId Then ' complain
MsgBox "Target selection must not include source item"
Exit Sub
End If
Next
End If
' OK, proceed
For Each oShp In ActiveWindow.Selection.ShapeRange
For Each oEffect In ActivePresentation.Slides(MySourceSlideIndex).TimeLine.MainSequence
If oEffect.Shape.Id = MySourceShapeId Then
Call TransferEffects(oEffect, ActiveWindow.Selection.SlideRange(1), oShp)
End If
Next
Next
End If
End Sub
Sub TransferEffects(oEffectA As PowerPoint.Effect, oSlide As Slide, oShape As PowerPoint.Shape)
Dim oEffectB As Effect
Dim IsMotion As Boolean
Set oEffectB = oSlide.TimeLine.MainSequence.AddEffect(oShape, oEffectA.EffectType)
DoEvents
On Error Resume Next
oEffectB.EffectParameters.Amount = oEffectA.EffectParameters.Amount
If Err.Number = 0 Then
Select Case oEffectA.EffectParameters.Color2.Type
Case Is = msoColorTypeScheme
oEffectB.EffectParameters.Color2.SchemeColor = oEffectA.EffectParameters.Color2.SchemeColor
Case Is = msoColorTypeRGB
oEffectB.EffectParameters.Color2.RGB = oEffectA.EffectParameters.Color2.RGB
End Select
End If
oEffectB.EffectParameters.Direction = oEffectA.EffectParameters.Direction
oEffectB.EffectParameters.FontName = oEffectA.EffectParameters.FontName
If oEffectA.EffectType <> msoAnimEffectGrowShrink Then
oEffectB.EffectParameters.Size = oEffectA.EffectParameters.Size
Else
oEffectB.Behaviors(1).ScaleEffect.ByX = oEffectA.Behaviors(1).ScaleEffect.ByX
oEffectB.Behaviors(1).ScaleEffect.ByY = oEffectA.Behaviors(1).ScaleEffect.ByY
End If
oEffectB.Timing.Duration = oEffectA.Timing.Duration
oEffectB.Timing.Accelerate = oEffectA.Timing.Accelerate
oEffectB.Timing.AutoReverse = oEffectA.Timing.AutoReverse
oEffectB.Timing.Decelerate = oEffectA.Timing.Decelerate
oEffectB.Timing.Restart = oEffectA.Timing.Restart
oEffectB.Timing.RewindAtEnd = oEffectA.Timing.RewindAtEnd
oEffectB.Timing.SmoothStart = oEffectA.Timing.SmoothStart
oEffectB.Timing.SmoothEnd = oEffectA.Timing.SmoothEnd
oEffectB.Exit = oEffectA.Exit
oEffectB.Timing.TriggerType = oEffectA.Timing.TriggerType
oEffectB.Timing.TriggerDelayTime = oEffectA.Timing.TriggerDelayTime
oEffectB.Timing.RepeatCount = oEffectA.Timing.RepeatCount
oEffectB.Timing.RepeatDuration = oEffectA.Timing.RepeatDuration
oEffectB.Timing.Speed = oEffectA.Timing.Speed
With oSlide.TimeLine.MainSequence
If oEffectA.Shape.HasTextFrame Then
Call .ConvertToAnimateBackground(oEffectB, oEffectA.EffectInformation.AnimateBackground)
Else
Call .ConvertToAnimateBackground(oEffectB, True)
End If
Select Case oEffectA.EffectInformation.AfterEffect
Case 2 ' Hide
Call .ConvertToAfterEffect(oEffectB, oEffectA.EffectInformation.AfterEffect)
Case 1 ' Dim
Call .ConvertToAfterEffect(oEffectB, oEffectA.EffectInformation.AfterEffect, oEffectA.EffectInformation.Dim)
Case 3 ' Hide on click
Call .ConvertToAfterEffect(oEffectB, oEffectA.EffectInformation.AfterEffect)
End Select
Call .ConvertToAnimateInReverse(oEffectB, oEffectA.EffectInformation.AnimateTextInReverse)
Call .ConvertToTextUnitEffect(oEffectB, oEffectA.EffectInformation.TextUnitEffect)
End With
Err.Clear
oEffectB.EffectParameters.Relative = oEffectA.EffectParameters.Relative
If Err.Number <> 0 Then
IsMotion = False
Else
IsMotion = True
End If
If IsMotion Then
oEffectB.Behaviors(1).MotionEffect.Path = oEffectA.Behaviors(1).MotionEffect.Path
On Error GoTo 0
If Sgn(Val(oEffectA.Behaviors(1).Timing.Speed)) = -1 Then
oEffectB.Behaviors(1).MotionEffect.Path = Left(oEffectA.Behaviors(1).MotionEffect.Path, 1) & " " & ReversePathInfo(Trim(Mid(oEffectA.Behaviors(1).MotionEffect.Path, 2)))
End If
End If
Exit Sub
errHandler:
If MsgBox(Err.Number & " " & Err.Description & vbCrLf & "Do you wish to continue?", vbQuestion + vbYesNo, "APP_NAME") = vbYes Then
Resume Next
End If
End Sub
Function ReversePathInfo(sPath As String) As String
Dim sItems() As String
Dim i As Integer
Dim sPositions() As String
Dim sReversedPath As String
Dim sClosedPath As String
If Not IsNumeric(Right(sPath, 1)) Then
sClosedPath = Right(sPath, 1)
sPath = Left(sPath, Len(sPath) - 1)
End If
sPath = Replace(sPath, " ", "~")
sItems = Split(sPath, "~")
ReDim sPositions(0 To UBound(sItems))
For i = LBound(sItems) To UBound(sItems)
If Left(sItems(i), 1) = "L" Then sPositions(i) = "L"
If Left(sItems(i), 1) = "C" Then sPositions(i) = "C"
If Left(sItems(i), 1) = "c" Then sPositions(i) = "c"
If Left(sItems(i), 1) = "l" Then sPositions(i) = "l"
Next i
For i = LBound(sPositions) To UBound(sPositions)
If LCase(sPositions(i)) = "c" Then
sPositions(i + 2) = sPositions(i)
sPositions(i) = ""
i = i + 2
End If
Next i
For i = UBound(sItems) To LBound(sItems) Step -1
Select Case Left(sItems(i), 1)
Case "L", "C", "c", "l"
sItems(i) = Trim(Mid(sItems(i), 2))
End Select
sReversedPath = sReversedPath & sItems(i) & " " & sPositions(i) & IIf(sPositions(i) <> "", " ", "")
Next i
ReversePathInfo = Trim(sReversedPath) & IIf(sClosedPath = "", "", " " & sClosedPath)
End Function