如何在 Power Point VBA 中创建点,在不同方向移动它们,同时保持它们与直线连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1705965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:57:37  来源:igfitidea点击:

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

vbacoordinatespowerpointpowerpoint-vba

提问by brilliant

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

我想在 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:

我想在主窗口中创建两个点 - 点 A 和点 B - 通过它们给定的坐标:例如,A (232, 464) 和 B (109, 567)。我不知道如何在 PowerPoint VBA 中做到这一点。我知道如何创建一条简单的直线。我使用这个宏代码:

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.

先感谢您。

回答by MikeD

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.

我在这里使用 SchemeColor 属性为形状着色,您当然也可以使用显式 RGB 颜色。

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

希望有帮助 祝你好运 MikeD