我正在尝试创建一个文本框,当在其中键入内容时,会自动在该框下添加该文本。 我知道这听起来没什么意义,但我真的需要这个,而且不知道该怎么做。 我将不胜感激。 我碰到过 但是,我尝试过它对我不起作用。 谢谢! ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我有一个包含许多矩形形状的文档。 我想在完全相同的地方用一个 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
尝试这个。 在我看来,您不需要创建一个 TextBox,您可以简单地更改现有的框,如下所示:
Dim shp As Shape
Dim Box As Shape
scount = ActiveDocument.Shapes.Count
For i = 1 To scount
Set shp = ActiveDocument.Shapes(i)
shp.TextFrame.TextRange.Text = "Some txt"
shp.Fill.ForeColor.RGB = RGB(255, 255, 255)
shp.Line.ForeColor.RGB = RGB(255, 255, 255)
shp.TextFrame.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
Next i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.