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:
- Set MouseClick action setting of a shape to the a MoveShape macro.
- The MoveShape macro
- Sets moving to true when you click the shape the first time.
- 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.
- 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
.
|
|