如何在Word VBA中提取形状坐标

发布于 2024-08-16 17:36:15 字数 194 浏览 3 评论 0原文

我正在尝试在 Word 中编写一个 VBA 宏,该宏将提取形状并在 Visio 中构建它们。我在获取文档中形状的 XY 坐标时遇到一些问题。我尝试使用形状对象的顶部和左侧属性。 Left 属性似乎工作正常,但 Top 似乎工作不正常。靠近页面顶部的形状可以与底部的形状具有相同的顶部,因此顶部似乎不适用于 Y 坐标,这对我来说没有意义。

有什么想法或建议吗?

I'm trying to write a VBA macro in Word that will extract shapes and build them in Visio. I'm having some trouble getting the X Y coordinates of the shape in the document. I have tried using the Top and Left properties of the shape objects. The Left property seems to work fine, but the Top doesn't seem to work properly. A shape near the top of the page can have the same top as a shape at the bottom, so the top doesn't seem to apply to the Y coordinate, which doesn't make sense to me.

Any thoughts or suggestions?

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

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

发布评论

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

评论(1

暮色兮凉城 2024-08-23 17:36:15

Jon,“顶部”属性应该随着形状改变位置而更新。您是否正在运行与此类似的脚本:

Sub getShapeXY()

    Dim shp As Shape
    Set shp = ThisDocument.Shapes(1)

    shpOffsetX = shp.Left
    shpWidth = shp.Width
    x = shpOffsetX + shpWidth

    shpOffsetY = shp.Top
    shpHeight = shp.Height
    y = shpOffsetY + shpHeight

    Debug.Print shpOffsetX & ": OffsetX, " & shpWidth & ": Width, " & x & ": X"
    Debug.Print shpOffsetY & ": OffsetY, " & shpHeight & ": Height, " & y & ": Y"

End Sub

Jon, the "Top" property should update as the shape changes location. Are you running a script similar to this:

Sub getShapeXY()

    Dim shp As Shape
    Set shp = ThisDocument.Shapes(1)

    shpOffsetX = shp.Left
    shpWidth = shp.Width
    x = shpOffsetX + shpWidth

    shpOffsetY = shp.Top
    shpHeight = shp.Height
    y = shpOffsetY + shpHeight

    Debug.Print shpOffsetX & ": OffsetX, " & shpWidth & ": Width, " & x & ": X"
    Debug.Print shpOffsetY & ": OffsetY, " & shpHeight & ": Height, " & y & ": Y"

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