工作“GetChartElement”的示例在PowerPoint 2007 VBA中 [英] working Example of "GetChartElement" in PowerPoint 2007 VBA
问题描述
有没有人有"GetChartElement"的工作示例? PowerPoint 2007 VBA中的API。
Does anyone has working example of "GetChartElement" API in PowerPoint 2007 VBA.
我已经在Excel 2007中使用了它,因为在Excel中可以找到Chart的WithEvents设置,你可以捕获"MouseDown"。有效地为您提供"X"的事件。和"Y"表示"Y"和"Y"。位置。但是在PowerPoint 2007中我们不能使用WithEvents for Chart。
I have used this in Excel 2007 and works find since in Excel you can have WithEvents setup for Chart and you can trap "MouseDown" event which acuratly provides you "X" and "Y" positions. But in PowerPoint 2007 we can not use WithEvents for Chart.
我试图捕获全局鼠标按下事件,如果ActiveWindow选择是Shape,那么我调用"GetCursorPos"寻找"X"的API和"Y"表示"Y"和"Y"。位置,但它提供了错误的信息。我总是得到"X" as -ve value。
I tried trapping global mouse down event, if ActiveWindow selection is Shape then I call "GetCursorPos" API to look for the "X" and "Y" position but it gives wrong information. I always get "X" as -ve value.
感谢是否有任何解决方案。
Appreciate if anyone has any solution for this.
问候,
Ramesh
推荐答案
嗨Ra1,
感谢您发帖,我们很乐意为您提供帮助。
Thank you for posting and we are glad to help with you.
据我所知,您可以使用"GetChartElement"。 PowerPoint 2007中的API通过VBA。以下是步骤和代码段,您可以尝试一下:
As far as I know, you can use "GetChartElement" API in PowerPoint 2007 via VBA. Below are the steps and code snippet, you can take a try:
1。插入名为clsPPTEvents的类模块并将以下代码放入其中:
1. Insert a class module named clsPPTEvents and put the following code in it:
Public WithEvents PPTEvent As Application
私有声明函数GetCursorPos Lib" user32" (lpPoint As POINTAPI)As long
私人类型POINTAPI
x As Long
y As Long
结束类型
Dim ret As Long
Public WithEvents PPTEvent As Application
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim ret As Long
Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
Dim mousePosition As POINTAPI
Dim ElementID As Long
Dim Arg1 As Long
Dim Arg2 As Long
昏暗的结果作为变体
使用Sel
如果.Type = ppSelectionShapes则为
Dim sr As ShapeRange
设置sr = .ShapeRange
如果sr.Type = msoChart则为
Dim sh As Shape
Dim slideNumber As Integer
slideNumber = ActiveWindow.View.Slide.SlideIndex
               设置sh = ActivePresentation.Slides(slideNumber).Shapes(sr.Name)
   Dim crt As Chart
设置crt = sh.Chart
H = ActiveWindow.Height
w = ActiveWindow.Width
ret = GetCursorPos(mousePosition)
x = mousePosition.x
y = mousePosition.y
crt.GetChartElement X,Y,ElementID,ARG1,Arg2所得
Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
Dim mousePosition As POINTAPI
Dim ElementID As Long
Dim Arg1 As Long
Dim Arg2 As Long
Dim result As Variant
With Sel
If .Type = ppSelectionShapes Then
Dim sr As ShapeRange
Set sr = .ShapeRange
If sr.Type = msoChart Then
Dim sh As Shape
Dim slideNumber As Integer
slideNumber = ActiveWindow.View.Slide.SlideIndex
Set sh = ActivePresentation.Slides(slideNumber).Shapes(sr.Name)
Dim crt As Chart
Set crt = sh.Chart
H = ActiveWindow.Height
w = ActiveWindow.Width
ret = GetCursorPos(mousePosition)
x = mousePosition.x
y = mousePosition.y
crt.GetChartElement x, y, ElementID, Arg1, Arg2
             &NBSP ;  MSGBOX(英寸×:"&安培; X&安培;",Y:"&安培; Y&安培; vbNewLine&安培; _
      &NBSP ;        " ElementID:"&安培; ElementID&安培;" ;, ARG1:"&安培; ARG1&安培;" ;, Arg2所得:"&安培; Arg2所得)
结束如果
结束如果是
结束与$
结束子
MsgBox ("X: " & x & ", Y: " & y & vbNewLine & _
"ElementID: " & ElementID & ", Arg1: " & Arg1 & ", Arg2: " & Arg2)
End If
End If
End With
End Sub
2。插入一个模块并将以下代码放入其中:
2. Insert a Module and put the following code in it:
Public newPPTEvents As new clsPPTEvents
Sub StartEvents()
; 设置newPPTEvents.PPTEvent =申请
结束子
子EndEvents()
设置newPPTEvents.PPTEvent = Nothing
End Sub
Public newPPTEvents As New clsPPTEvents
Sub StartEvents()
Set newPPTEvents.PPTEvent = Application
End Sub
Sub EndEvents()
Set newPPTEvents.PPTEvent = Nothing
End Sub
3。然后,您可以执行StartEvents方法。单击图表时,您可以获得有关postion ,ElmentID和其他一些参数的消息。
3. Then, you can execute the StartEvents method. When clicking on the chart, you can get the message about the postion , ElmentID and some other arguments.
此外,这里有关于GetChartElement方法的MSDN文章:
http://msdn.microsoft.com/en-us/library/aa195740(office。 11).aspx
Besides, here is the MSDN article about the GetChartElement method: http://msdn.microsoft.com/en-us/library/aa195740(office.11).aspx
我希望这可以帮助你,并在你尝试后随时跟进。
I hope this can help you and feel free to follow up after you have tried.
最好的问候,
这篇关于工作“GetChartElement”的示例在PowerPoint 2007 VBA中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!