-
2007 VBA Code is not working in 2010
I have a code I use in 2007 PowerPoint, which is not working in PowerPoint 2010 (32 Bit). The macro is supposed to identify a shape on a mouse click, move it and drop it on the second mouse click. In 2010 it will move the shape, however will not release it. <Code follows>
Any ideas?
[VBA]Module:
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hDC As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nIndex As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Private Const TWIPSPERINCH = 1440
Private Declare Function SetTimer Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long) As Long
Type Point
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As Point) As Long
Private XPixelsPerInch As Long
Private YPixelsPerInch As Long
Private Ratio As Single
Private Moving As Boolean
Private DragShp As Shape
Private TimerId As Long
Private HostObj As HostClass
Private OrigShpLeft As Single
Private OrigShpTop As Single
Private OrigMouseLocation As Point
Sub MoveShape(ByVal Shp As Shape)
Dim hDC As Long
On Error Resume Next
If SlideShowWindows.Count > 0 Then
If Moving Then
EndMoveShape
Else
hDC = GetDC(0)
XPixelsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
YPixelsPerInch = GetDeviceCaps(hDC, LOGPIXELSY)
ReleaseDC 0, hDC
Ratio = Shp.Parent.Parent.SlideShowWindow.View.Zoom / 100#
Set DragShp = Shp
OrigShpLeft = Shp.Left
OrigShpTop = Shp.Top
GetCursorPos OrigMouseLocation
StartTimer
Moving = True
Set HostObj = New HostClass
End If
End If
End Sub
Sub EndMoveShape()
On Error Resume Next
Set HostObj = Nothing
Moving = False
StopTimer
Set DragShp = Nothing
End Sub
Private Sub StartTimer()
On Error Resume Next
TimerId = SetTimer(0, 0, 10, AddressOf TimerProc)
End Sub
Private Sub StopTimer()
On Error Resume Next
KillTimer 0, TimerId
End Sub
Private Sub TimerProc(ByVal hWnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long)
Dim CurMouseLocation As Point
Dim DeltaX As Single
Dim DeltaY As Single
On Error Resume Next
If Moving Then
GetCursorPos CurMouseLocation
DeltaX = (CurMouseLocation.X - OrigMouseLocation.X) * _
TWIPSPERINCH / 20 / XPixelsPerInch / Ratio
DeltaY = (CurMouseLocation.Y - OrigMouseLocation.Y) * _
TWIPSPERINCH / 20 / XPixelsPerInch / Ratio
DragShp.Left = OrigShpLeft + DeltaX
DragShp.Top = OrigShpTop + DeltaY
End If
End Sub
Host Class:
Option Explicit
Private WithEvents HostApp As PowerPoint.Application
Private Sub Class_Initialize()
Set HostApp = PowerPoint.Application
End Sub
Private Sub HostApp_SlideShowBegin(ByVal Wn As SlideShowWindow)
End Sub
Private Sub HostApp_SlideShowEnd(ByVal Pres As Presentation)
MoveShapeModule.EndMoveShape
End Sub
Private Sub HostApp_SlideShowNextBuild(ByVal Wn As SlideShowWindow)
End Sub
Private Sub HostApp_SlideShowNextClick(ByVal Wn As SlideShowWindow, ByVal nEffect As Effect)
End Sub
Private Sub HostApp_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
End Sub
Private Sub HostApp_SlideShowOnNext(ByVal Wn As SlideShowWindow)
End Sub
Private Sub HostApp_SlideShowOnPrevious(ByVal Wn As SlideShowWindow)
End Sub
Private Sub HostApp_WindowActivate(ByVal Pres As Presentation, ByVal Wn As DocumentWindow)
End Sub
Private Sub HostApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
End Sub
Private Sub HostApp_WindowBeforeRightClick(ByVal Sel As Selection, Cancel As Boolean)
End Sub
Private Sub HostApp_WindowDeactivate(ByVal Pres As Presentation, ByVal Wn As DocumentWindow)
End Sub
Private Sub HostApp_WindowSelectionChange(ByVal Sel As Selection)
End Sub[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules