Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Powerpoint 2010, how to hide form and click on slide to return X-Y coords

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I have a form which I am loading from a Quick access tool bar.
I am able to create various Organization charts by clicking various buttons on this form and choosing different managers.

I would like to be able to allow the user to pick a spot on the slide where they want a sub Org chart to go then click another button to actually place it there.
I know how to place something, I just need to know how to hide the form and have them pick a spot with a mouse click then have it get those X-Y coords whereby I pass that to my sub org creation routine.

TIA


DougP
 
hi,

Check out the GetChartElement method

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
BTW, in 2007+, the same Chart Object Model is used in all Office applications.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ok Skip, I have this code in place, but don't know how to implement it. unlike in a form there are Activate and Mouse move or click events.
I want to click on a slide and get the Y-X coords. ths slide could be blank so there is no chart, which appears to be what this code is for. Also unlike Word and Excel which both have "default" file. i.e Normal.dot and Personal.xls. PowerPoint does not have a file, or does it.

this is in a class
Code:
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
    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
                MsgBox ("X: " & x & ", Y: " & y & vbNewLine & _
                "ElementID: " & ElementID & ", Arg1: " & Arg1 & ", Arg2: " & Arg2)
            End If
        End If
    End With
End Sub

this is in a module

Code:
Public newPPTEvents As New clsPPTEvents
Sub StartEvents()
    Set newPPTEvents.PPTEvent = Application
End Sub
Sub EndEvents()
    Set newPPTEvents.PPTEvent = Nothing
End Sub


DougP
 
This is all from John Walkenbach's Excel Charts my go-to bible for charts.
[tt]
1. Create a class module

2. Declare a public Chart object
Code:
'in class module
Public WithEvents MyChart As Chart

3. Connect the declared object to your chart
Code:
'in module
Dim myClassModule As New Class1

4. Execute a statement to instantiate the object
Code:
'in module
Sub InitializeChart()
    Set myClassModule.MyChart = ActiveSheet.ChartObjects(1).Chart
End Sub

5. Write event procedures for the chart class
Code:
'in class module
Private Sub MyChart_Activate()
    WriteEvent "Chart Activated"
End Sub

Private Sub MyChart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
    Dim ElementID As Long, ID As String
    Dim a As Long, b As Long
    ActiveChart.GetChartElement X, Y, ElementID, a, b
    Application.StatusBar = "Mouse coordinates: " & X & ", " & Y
End Sub



Private Function GetChartElementName(ElementID, Optional arg1, Optional arg2) As String
    Select Case ElementID
        Case xlAxis
            GetChartElementName = "Axis " & arg1 & " " & arg2
        
        Case xlAxisTitle
            GetChartElementName = "Axis Title " & arg1 & " " & arg2
        
        Case xlChartArea
            GetChartElementName = "ChartArea"
            
        Case xlChartTitle
            GetChartElementName = "ChartTitle"
            
        Case xlCorners
            GetChartElementName = "Corners"
        
        Case xlDataLabel
            If arg2 = -1 Then
                GetChartElementName = "Data Labels " & arg1
            Else
                GetChartElementName = "Data Label " & arg1 & " " & arg2
            End If
        
        Case xlDataTable
            GetChartElementName = "Data Table"
        
        Case xlDisplayUnitLabel
            GetChartElementName = "Display Unit Label " & arg1 & " " & arg2
        
        Case xlDownBars
            GetChartElementName = "Down Bars " & arg1
        
        Case xlDropLines
            GetChartElementName = "Drop Lines " & arg1
            
        Case xlErrorBars
            GetChartElementName = "Error Bars " & arg1
        
        Case xlFloor
            GetChartElementName = "Floor"
        
        Case xlHiLoLines
            GetChartElementName = "HiLoLines " & arg1
            
        Case xlLegend
            GetChartElementName = "Legend"
        
        Case xlLegendEntry
            GetChartElementName = "LegendEntry " & arg1
            
        Case xlLegendKey
            GetChartElementName = "LegendKey " & arg1
        
        Case xlMajorGridlines
            GetChartElementName = "Major Gridlines " & arg1 & " " & arg2
        
        Case xlMinorGridlines
            GetChartElementName = "Minor Gridlines " & arg1 & " " & arg2
            
        Case xlNothing
            GetChartElementName = "Nothing"
        
        Case xlPivotChartDropZone
            GetChartElementName = "Pivot Chart Drop Zone " & arg1
                    
        Case xlPivotChartFieldButton
            GetChartElementName = "Pivot Chart Field Button" & arg1 & " " & arg2
            
        Case xlPlotArea
            GetChartElementName = "PlotArea"
        
        Case xlRadarAxisLabels
            GetChartElementName = "RadarAxisLabels " & arg1
        
        Case xlSeries
            If arg2 = -1 Then
                GetChartElementName = "Series " & arg1
            Else
                GetChartElementName = "Series " & arg1 & " " & arg2
            End If
        
        Case xlSeriesLines
            GetChartElementName = "SeriesLines " & arg1
            
        Case xlShape
            GetChartElementName = "Shape " & arg1
            
        Case xlTrendline
            GetChartElementName = "Trendline" & arg1
        
        Case xlUpBars
            GetChartElementName = "UpBars " & arg1
        
        Case xlWalls
            GetChartElementName = "Walls"
        
        Case xlXErrorBars
            GetChartElementName = "XErrorBars " & arg1
        
        Case xlYErrorBars
            GetChartElementName = "YErrorBars " & arg1
        
        Case Else: GetChartElementName = "Some unknown thing"
    End Select
End Function

6. Execute a statement to destroy the object and stop monitoring events
Code:
'in module
Sub DisconnectChart()
    Set myClassModule = Nothing
End Sub

[/tt]



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top