Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lifetime of variables in powerpoint

Status
Not open for further replies.

RodP

Programmer
Jan 9, 2001
109
GB
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
 



Have you tried dragging the module from one VBA Project into the other?

Skip,

[glasses] [red][/red]
[tongue]
 
Hiya Skip,

Thanks for the suggestion but I need to keep the macro in the 'powerpoint macros.ppt' file as this and all the other macros I've written need to be readily available to use on any ppt file I'm working on (just like using personal.xls to store all your excel macros).

One idea I did have was to use a non modal form and have the copy and paste buttons on that, thus keeping the module running whilst I go through the various pages re formatting all the objects. I'd like though to try and learn how to do it using variables though as that would be useful in many other cases.

Hope some one can help.

Many thanks

Rodp
 
Why not create (save as 'ppa' file) powerpoint add-in and install it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top