English 中文(简体)
How to create dots in Power Point VBA, move them around in different directions while keeping them connected with straight lines?
原标题:

There is one thing I want to do in PowerPoint VBA.

I want to create two dots in the main window - dot A and dot B - by their given coordinates: for example, A (232, 464) and B (109, 567). I don t know how to do it in PowerPoint VBA. I know how to create a simple straight line. I use this macro code for that:

Sub CreateLine()
    ActiveWindow.Selection.SlideRange.Shapes.AddLine(192#, 180#, 360#, 252#).Select
End Sub

But I still don t know how what code I would need to create just dots, not lines.

Then, I want to move those dots somehow. Again, I know hot to move whole lines or other objects - for that I use this code:

Sub move()
    ActiveWindow.Selection.ShapeRange.IncrementLeft 6#
End Sub

But I don t know how to move dots, especially if I want to move one dot one way (for example, move it up) and the other dot another way (for example, move it to the left).

Why do I want to do it? Because later I am planning to keep those dots "connected" by straight lines, no matter which directions I move those dots.

If you know the answer, please share it with me here.

Thank you in advance.

最佳回答

in order to create a "dot" you use the "oval" shape, i.e. a small circle, where you can set line and fill colors to the same, i.e.

Sub DoDot()

     create a circular shape    
    ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, 144.5, 150.88, 11.38, 11.38).Select

    With ActiveWindow.Selection.ShapeRange

          color it
        .Line.ForeColor.SchemeColor = ppAccent1
        .Line.Visible = msoTrue
        .Fill.ForeColor.SchemeColor = ppAccent1
        .Fill.Visible = msoTrue
        .Fill.Solid

          move it
        .Top = 10
        .Left = 10

    End With
End Sub

I used the SchemeColor property here to color the shape, you can of course use an explicit RGB color as well.

Later on, if you want to connect dots with lines, you will need to either move the dots and (re)create lines in between them, or you use dot-shaped line end types

Sub LineWithEndType()
    ActiveWindow.Selection.SlideRange.Shapes.AddLine(195.62, 162.25, 439.38, 309.75).Select
    With ActiveWindow.Selection.ShapeRange
        .Line.Visible = msoTrue
        .Fill.Transparency = 0#
        .Line.BeginArrowheadStyle = msoArrowheadOval
        .Line.EndArrowheadStyle = msoArrowheadOval
        .Line.BeginArrowheadLength = msoArrowheadLong
        .Line.BeginArrowheadWidth = msoArrowheadWide
        .Line.EndArrowheadLength = msoArrowheadLong
        .Line.EndArrowheadWidth = msoArrowheadWide
    End With

End Sub

Hope that helps Good luck MikeD

问题回答

暂无回答




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签