Académique Documents
Professionnel Documents
Culture Documents
===================================================================================
' Drag & Drop Macro
'
' Original code developed by Hans W. Hofmann
' Modified by Jamie Garroch of YOUpresent Ltd.
' Visit us online at http://youpresent.co.uk
'
' Standard operation during a slide show:
'
' Mode 1 : Left click a shape with the macro assigned to it to pick it up and move
it.
' Click again to drop it (not working in PowerPoint 2010 so 5 second timer
' added as a temporary workaround which can be chagned by setting the constant
' "DropInSeconds" to a value in seconds in the below "Drag" procedure.
' Mode 2 : While holding Shift and Alt, left-click to calculate the text based
formula
' within the shape.
'
===================================================================================
Option Explicit
dx = GetSystemMetrics(SM_SCREENX)
dy = GetSystemMetrics(SM_SCREENY)
Drag oShp
' Paste the original text while maintaining its formatting, back to the shape
If oShp.HasTextFrame Then oShp.TextFrame.TextRange.Paste
DoEvents
End Sub
StartTime = Timer
While dragMode
GetCursorPos mPoint
oShp.Left = (mPoint.x - sx) / dx - oShp.Width / 2
oShp.Top = (mPoint.y - sy) / dy - oShp.Height / 2
' Comment out the next line if you do NOT want to show the countdown text
within the shape
If oShp.HasTextFrame Then oShp.TextFrame.TextRange.Text = CInt(DropInSeconds -
(Timer - StartTime))
DoEvents
If Timer > StartTime + DropInSeconds Then dragMode = False
Wend
DoEvents
End Sub
' Create an array of text strings by splitting the shape text concatenated with
"=" using "=" as a delimiter
' The additon of "=" guarantees that the array has at least 2 elements, in
positions 0 and 1
FormulaArray = Split(oShp.TextFrame.TextRange.Text & "=", "=")
' Replace all "," with "." in the first array entry (converting decimal format
from EU to UK?)
While InStr(FormulaArray(0), ",") > 0
FormulaArray(0) = Replace(FormulaArray(0), ",", ".")
Wend
' If there is some text in the first array cell then Evaluate it using Excel
and save the result in the 2nd array element
' Note: Evaluate is not an Excel function but a formula auditing tool which
shows you exactly how the result is calculated
If FormulaArray(0) > "" Then
FormulaArray(1) = xl.Evaluate(FormulaArray)
' Concatenate the formula with the Evaluate text and save it back to the
shape
oShp.TextFrame.TextRange.Text = FormulaArray(0) & "=" & FormulaArray(1)
End If
xl.Quit: Set xl = Nothing
' Nudge the shape up and back down to the same position (forcing the slide to
be refreshed when DoEvents is called)
oShp.Top = oShp.Top + 1: oShp.Top = oShp.Top - 1
End If
DoEvents
End Sub