0

我在 Word 文档中有一个形状,需要将其移动到书签位置。

我尝试使用“left”和“top”属性,但是,这不起作用,因为据我所知,书签没有“left”和“right”属性。

我曾尝试使用剪切和粘贴,但这不适用于形状。

以下是创建形状的代码:

Set shp = ActiveDocument.Content.InlineShapes.AddOLEControl("Forms.CommandButton.1")

With ActiveDocument.InlineShapes(1).OLEFormat.Object
    .Caption = "Test"
    .Height = 30
    .Width = 44
End With

With ActiveDocument.InlineShapes(1).ConvertToShape
    .Name = "Test1"
    .ZOrder (msoBringInFrontOfText)
End With
4

2 回答 2

1

除了使用书签,您可以在文档的某处使用绝对位置吗?

        Dim Test1 As Shape

        Set Test1 = ActiveDocument.Shapes("Test1")

        With Test1
                .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
                .RelativeVerticalPosition = wdRelativeVerticalPositionPage
                .Left = InchesToPoints(6.889)
                .Top = InchesToPoints(0.374)
        End With


        End Sub
于 2012-11-29T02:13:52.973 回答
0

这是一个非常古老的线程,但基本前提仍然有效,并且可以使用 VBA 在带书签的位置(此处为名为“bmShape”的书签)插入控件,如下所示。

Dim oRng As Range
Dim oShp As InlineShape
Set oRng = ActiveDocument.Bookmarks("bmShape").Range
oRng.Text = ""
Set oShp = oRng.InlineShapes.AddOLEControl("Forms.CommandButton.1")
oRng.End = oRng.End + 1
oRng.Bookmarks.Add "bmShape"

With oShp.OLEFormat.Object
    .Caption = "Test"
    .Height = 30
    .Width = 44
End With

With oShp.ConvertToShape
    .Name = "Test1"
    .WrapFormat.Type = wdWrapSquare
    .WrapFormat.Side = wdWrapBoth
End With
于 2018-01-24T09:46:46.413 回答