Move Shape using Mouse during Slide Show

The sample code below shows how to develop VBA code to move shapes during slide show using the mouse. The process to move the shape would be to click the shape to pick it up, then move the mouse to place the shape at a new location and then finally click the shape again to drop it at that new location.

The logic is:

  1. Set MouseClick action setting of a shape to the a MoveShape macro.
  2. The MoveShape macro
    1. Sets moving to true when you click the shape the first time.
    2. Notes down the shape's location in OrigShpLeft and OrigShpTop variables and also the mouse location in OrigMouseLocation variable. A key point to note here is that while the values of OrigShpLeft and OrigShpTop are relative to the slide and in points, the OrigMouseLocation is relative to the desktop and in pixels. So, when we want to calculate the new location for the shape, we need to convert the mouse coordinates by converting from pixels to points as described in ConvertPixelsToPoints macro.
    3. Start a timer that runs a procedure every 10 milliseconds. The timer macro looks-up the current mouse position and calculates the difference from the original position. This difference is applied to the shape's position thus moving the shape to follow the mouse.

The demo presentation that has the code described above is available for download here Download.

Contact OfficeOne on email at Copyright © 2001-2023 OfficeOne. All rights reserved.