VBA 在 Word 中总是将文本框缩进设置为相同的错误值

VBA in Word always sets textbox indents to same wrong value

我正在尝试使用 VBA 在 Word 中创建一个文本框,但 Word 始终创建文本框,左右缩进相距约 5 英寸,每边缩进约 1 英寸。我已经尝试了所有我能想到的 - 自己设置缩进(失败),首先清除所有段落格式(失败),清除所有制表位(失败),并在最后第二次重置 left/right 缩进我的代码。

当我在创建的文本框中单击时,我可以看到制表位停止,如果我手动移动它们,里面的文本会相应地响应。有谁知道我做错了什么(或没有做什么)? ShapeTboxCreate 子例程只是正常创建文本框,但在将参数(以英寸为单位)传递给 .Shapes.AddShape(msoTextBox,...) 函数之前将参数(以英寸为单位)转换为点。

谢谢。

   Set tbox = ShapeTboxCreate(0.5, 0.37, 7.5, 0.75)
   tbox.name = "Header Title Box"
   selection.ClearParagraphAllFormatting
   selection.Collapse wdCollapseStart
   tbox.TextFrame.TextRange.ParagraphFormat.TabStops.ClearAll
   tbox.TextFrame.TextRange.ParagraphFormat.LeftIndent = 0
   tbox.TextFrame.TextRange.ParagraphFormat.RightIndent = 0
   tbox.TextFrame.TextRange.Text = "My Text Here"

这是子程序。它将参数(以英寸为单位)转换为点并创建矩形。

Function ShapeRectCreate(left As Single, top As Single, width As Single, _
   height As Single) As Shape
Dim shp As Shape
Set shp = ActiveDocument.shapes.AddShape(msoShapeRectangle, 0, 0, _
      InchesToPoints(width), InchesToPoints(height))
shp.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
shp.RelativeVerticalPosition = wdRelativeVerticalPositionPage
shp.left = InchesToPoints(left)
shp.top = InchesToPoints(top)
Set ShapeRectCreate = shp
End Function

问题出在创建文本框的代码中。这段代码看起来应该可以工作,但它创建了一个带有笑脸的椭圆,嵌入到文本框中。选项卡由笑脸字符设置。我知道这很奇怪。

ActiveDocument.Shapes.AddShape(msoTextBox,...)

当我用这段代码替换上面的代码时,一切都按预期工作:

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal,...)

也许有一天这会对某人有所帮助。