PPT2000: How to Move Objects During a Slide Show

ID: Q242181


The information in this article applies to:
  • Microsoft Office 2000
  • Microsoft PowerPoint 2000


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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

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.
  1. In slide view, click to select the shape or frame whose name you want to retrieve.


  2. On the Tools menu, point to Macro, and then click Visual Basic Editor.


  3. If the Immediate window is not visible, click Immediate Window on the View menu.


  4. 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 : kbdta kbdtacode OffVBA KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: October 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.