我有一个包含许多矩形形状的文档。我想在完全相同的位置用TextBox替换每个。我的起点是使用一个我想用文本框替换的现有已知形状(稍后我将添加进一步的自动化功能来处理所选形状或所有形状)。
到目前为止,这是我的代码:
Sub Macro3()
'
' Macro3 Macro
'
'
Dim shp As Shape
Dim Box As Shape
For Each shp In ActiveDocument.Shapes.Range(Array("Group 1928"))
shp.Select
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=shp.Left, Top:=shp.Top, Width:=shp.Width, Height:=shp.Height)
Box.RelativeHorizontalPosition = shp.RelativeHorizontalPosition
Box.RelativeVerticalPosition = shp.RelativeVerticalPosition
Box.TextFrame.TextRange.Text = "Some text"
Next shp
End Sub
我尝试设置许多其他属性,但文本框始终出现并停留在文档页面的顶部中心。
感谢您提供的任何指导。
问候蒂姆
例如:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, rt As Long, rl As Long, wf As Long, Shp As Shape
With ActiveDocument
For i = .Shapes.Count To 1 Step -1
With .Shapes(1)
If .Type = msoAutoShape Then
wf = .WrapFormat.Type
rt = .TopRelative
rl = .LeftRelative
Set Shp = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height, Anchor:=.Anchor)
With Shp
.WrapFormat.Type = wf
.TopRelative = rt
.LeftRelative = rl
.TextFrame.TextRange.Text = "Hello World"
End With
.Delete
End If
End With
Next
End With
Application.ScreenUpdating = True
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句