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

发布于 2024-08-10 03:35:53 字数 655 浏览 3 评论 0原文

我想在 PowerPoint VBA 中做一件事。

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

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

但我仍然不知道我需要什么代码来创建点,而不是线。

然后,我想以某种方式移动这些点。 再说一次,我知道移动整行或其他对象很热 - 为此我使用以下代码:

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

但我不知道如何移动点,特别是如果我想以一种方式移动一个点(例如,向上移动)并且另一个点以另一种方式(例如,将其向左移动)。

我为什么要这么做? 因为后来我计划让这些点通过直线“连接”起来,无论我向哪个方向移动这些点。

如果您知道答案,请在这里与我分享。

先感谢您。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-08-17 03:35:53

为了创建一个“点”,您使用“椭圆形”形状,即一个小圆圈,您可以将线条和填充颜色设置为相同,即

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

我在这里使用了SchemeColor属性来为形状着色,您当然可以使用以及明确的 RGB 颜色。

稍后,如果您想用线连接点,您将需要移动点并
(重新)在它们之间创建线条,或者使用点状线条末端类型

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

希望有帮助
祝你好运麦克D

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文