【问题标题】:vba GetCursorPos User-defined type not defined errorvba GetCursorPos 用户定义类型未定义错误
【发布时间】:2020-07-18 20:56:23
【问题描述】:

我正在让 label1 在 powerpoint 中用鼠标移动。 但我得到用户定义类型未定义错误。

代码:

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Type POINTAPI
 left As Long
 top As Long
End Type

Dim Xoff, Yoff As Long
Dim dragstate As Boolean
Private Sub Label1_Click()

End Sub

Private Sub Label1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
dragstate = True
Xoff = X
Yoff = Y
End Sub

Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If dragstate = True Then
 With Label1
  Dim mouse As POINTAPI
  GetCursorPos mouse
  .top = mouse.top / 2 - Xoff
  .left = mouse.left / 2 - Yoff
 End With
End If
End Sub

Private Sub Label1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
dragstate = False
ActivePresentation.SlidesShowWindows.View.GotoSlide ActivePresentation.SlidesShowWindow.View.CurrentShowPosition
End Sub

enter image description here 有人可以帮我吗?

【问题讨论】:

  • 您在 32 位应用程序中工作吗?如果没有,请尝试Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  • 我在 32 位工作
  • 试试Dim Xoff As Long, Yoff As Long。否则,Xoff 被声明为 As Variant
  • 将 .SlidesShowWindows 的每个实例替换为 .SlideShowWindow 并将 Label1 替换为 With ActivePresentation.Slides(1).Shapes("Label1") 或其他引用 Label1 形状的方式。
  • 好的..我会试试的

标签: vba types powerpoint defined user-defined


【解决方案1】:

您似乎将该代码放入 Slide1 中。在这种情况下,您需要使用 Private 声明用户定义的类型。

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 只要 私有类型 POINTAPI 离开了只要 顶只要长 结束类型

或者您需要将用户定义的类型声明移动到标准模块中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多