How to create dots in Power Point VBA, move them around in different directions while keeping them connected with straight lines?

StackOverflow https://stackoverflow.com/questions/1705965

Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top