Hi Everyone,
I've written a routine in powerpoint which records dimensions of an object so that they can then be used / pasted onto other objects. The routine consists of 2 macros and all works fine whilst i'm working in that file. But there is a problem when I come to reference these two macros from another file (ie create a custom button which references the macros). The problem is that when the first macro stops running the variables are lost because the ppt file in question is not actually open. I've tried using public and static statements but this doesn't seem to help.
Is there a way to get round this by lengthening the lifetime of the variables so that whilst powerpoint remains open the variables are still alive or do I need to completely change the macros? Any ideas would be most welcome.
Many thanks in advance
RodP
Here are the macros in my 'powerpoint macros.ppt' file:
--------------------
Sub Copy_Object_Dimensions()
Dim Osld As Slide
Dim oShp As Shape
Dim oShpH As Long
Dim oShpW As Long
Dim oShpL As Long
Dim oShpT As Long
response = MsgBox("Please select an object to copy the size and dimension settings", vbOKCancel)
If response = vbCancel Then Exit Sub
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then
MsgBox ("Please select one and only one shape, then try again.")
Exit Sub
End If
With ActiveWindow.Selection.ShapeRange(1)
Set Osld = Windows(1).View.Slide
ActiveWindow.View.GotoSlide (Osld.SlideIndex)
oShpH = .Height
oShpW = .Width
oShpL = .Left
oShpT = .Top
End With
repsonse = MsgBox("Are you ok to use these dimensions?" & Chr(10) & "Height: " & oShpH & Chr(10) & "Width: " & oShpW & Chr(10) & "Left pos: " & oShpL & Chr(10) & "Top pos: " & oShpT, vbOKCancel)
If response = vbOK Then
End If
End Sub
--------------
Sub Paste_Object_Dimensions()
Dim Osld As Slide
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then
MsgBox ("Please select one and only one shape, then try again.")
Exit Sub
End If
MsgBox ("Are you ok to use these dimensions?" & Chr(10) & "Height: " & oShpH & Chr(10) & "Width: " & oShpW & Chr(10) & "Left pos: " & oShpL & Chr(10) & "Top pos: " & oShpT)
With ActiveWindow.Selection.ShapeRange(1)
Set Osld = Windows(1).View.Slide
ActiveWindow.View.GotoSlide (Osld.SlideIndex)
.Height = oShpH
.Width = oShpW
.Left = oShpL
.Top = oShpT
End With
End Sub
I've written a routine in powerpoint which records dimensions of an object so that they can then be used / pasted onto other objects. The routine consists of 2 macros and all works fine whilst i'm working in that file. But there is a problem when I come to reference these two macros from another file (ie create a custom button which references the macros). The problem is that when the first macro stops running the variables are lost because the ppt file in question is not actually open. I've tried using public and static statements but this doesn't seem to help.
Is there a way to get round this by lengthening the lifetime of the variables so that whilst powerpoint remains open the variables are still alive or do I need to completely change the macros? Any ideas would be most welcome.
Many thanks in advance
RodP
Here are the macros in my 'powerpoint macros.ppt' file:
--------------------
Sub Copy_Object_Dimensions()
Dim Osld As Slide
Dim oShp As Shape
Dim oShpH As Long
Dim oShpW As Long
Dim oShpL As Long
Dim oShpT As Long
response = MsgBox("Please select an object to copy the size and dimension settings", vbOKCancel)
If response = vbCancel Then Exit Sub
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then
MsgBox ("Please select one and only one shape, then try again.")
Exit Sub
End If
With ActiveWindow.Selection.ShapeRange(1)
Set Osld = Windows(1).View.Slide
ActiveWindow.View.GotoSlide (Osld.SlideIndex)
oShpH = .Height
oShpW = .Width
oShpL = .Left
oShpT = .Top
End With
repsonse = MsgBox("Are you ok to use these dimensions?" & Chr(10) & "Height: " & oShpH & Chr(10) & "Width: " & oShpW & Chr(10) & "Left pos: " & oShpL & Chr(10) & "Top pos: " & oShpT, vbOKCancel)
If response = vbOK Then
End If
End Sub
--------------
Sub Paste_Object_Dimensions()
Dim Osld As Slide
If ActiveWindow.Selection.ShapeRange.Count <> 1 Then
MsgBox ("Please select one and only one shape, then try again.")
Exit Sub
End If
MsgBox ("Are you ok to use these dimensions?" & Chr(10) & "Height: " & oShpH & Chr(10) & "Width: " & oShpW & Chr(10) & "Left pos: " & oShpL & Chr(10) & "Top pos: " & oShpT)
With ActiveWindow.Selection.ShapeRange(1)
Set Osld = Windows(1).View.Slide
ActiveWindow.View.GotoSlide (Osld.SlideIndex)
.Height = oShpH
.Width = oShpW
.Left = oShpL
.Top = oShpT
End With
End Sub