Microsoft KB Archive/242181

= PPT2000: How to Move Objects During a Slide Show =

Article ID: 242181

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft PowerPoint 2000 Standard Edition

-



This article was previously published under Q242181



SUMMARY
During a slide show, you may want to change the positions of an object or hide and display it on command. This article demonstrates one way to do this with Microsoft Visual Basic for Applications (VBA) macros.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Getting Object Names
Although you can work with the index position for visible objects, if you plan to hide and make visible a shape or text frame, you need to find out the name of the object.  In slide view, click to select the shape or frame whose name you want to retrieve. On the Tools menu, point to Macro, and then click Visual Basic Editor. If the Immediate window is not visible, click Immediate Window on the View menu.  Type the following line of code in the Immediate window, and press ENTER: Debug.Print ActiveWindow.Selection.ShapeRange.Name This returns the name of the selected object, and prints it below the command. This is the actual name of the slide object. 

Changing The Position Of Objects
The following code fragment demonstrates how to change the location of a shape to another location on the slide: With ActivePresentation.Slides(1).Shapes("Rectangle 2") .Left = 210 .Top = 30 End With All objects' positions are referenced by their upper-left corner; these values are in points (72 points per inch). The standard PowerPoint presentation is 720 points wide, and 540 points tall. The upper-left corner is Left = 0, and Top = 0.

The following sample macro moves "Rectangle 2" from the lower-right corner of the slide, to the upper-left corner of the slide: Sub MoveBox Dim i As Long

' This moves Rectangle 2 across the slide in ten steps. '  With ActivePresentation.Slides(1).Shapes("Rectangle 2") For i = 1 To 10 ' These calculations will move the object fast at first, but ' slowing down until it crawls into the corner. '        .Left = 720 / i         .Top = 540 / i   ' Refresh the slide after every movement, otherwise the ' shape will simply appear in the upper-left corner. '        SlideShowWindows(1).View.GotoSlide 1 Next i  End With End Sub Another way to move an object is to rotate it around its center. This can make for some interesting effects. The following code sample demonstrates how you could do it: For r = 0 To 720 Step 20 ActivePresentation.Slides(1).Shapes("AutoShape 2").Rotation = r     SlideShowWindows(1).View.GotoSlide 1, msoFalse Next r Rotation is a read/write property. As input, it takes a number of type Single as the number of degrees rotation you want to apply to the shape. A positive value rotates the object clockwise, a negative value rotates it counterclockwise. In the previous code sample, the object is rotated clockwise.

Hiding and Showing Objects
Another way to alter a slide object is to make it appear or disappear. To do this, you simply alter the Visible property of the shape: ActivePresentation.Slides(1).Shapes("AutoShape 2").Visible = msoTrue Again, please note that if you make an object invisible, the only way you can make it visible directly is by using the name of the object, instead of using the index value assigned to the shape; the index value can change if the z-order position of the object changes.

Additional query words: vba

Keywords: kbdtacode kbhowto kbprogramming KB242181

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.