[英]Inserting a text box with a field (file name)
我正在使用 Word、Office 2010 和这个宏,它可以插入一个带有文本“ABC”的文本框。
Sub AddATextBox()
Dim Box As Shape
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=20, Top:=780, Width:=100, Height:=100)
With Box
.TextFrame.TextRange.Text = "ABC"
.Line.Visible = msoFalse
Box.TextFrame.TextRange.Font.Name = "Arial"
Box.TextFrame.TextRange.Font.Size = 6
End With
End Sub
我希望此宏将字段“文件名”插入文本框中,而不是文本“ABC”。 最好没有文件扩展名,但如果它很复杂,那么我可以忍受它。
怎么做? 谢谢
下面的代码将在页面底部插入一个文本框,并将活动文档的名称写入其中。 请注意,该形状不是页脚的一部分。 它锚定在主文档正文中。
Sub InsertATextBox()
Dim Box As Shape
Dim Sp() As String
Debug.Print ActiveDocument.Name
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=20, Top:=780, Width:=120, Height:=12)
Sp = Split(ActiveDocument.Name, ".")
ReDim Preserve Sp(UBound(Sp) - 1)
With Box
With .TextFrame.TextRange
.Text = Join(Sp, ".")
.Font.Name = "Arial"
.Font.Size = 6
End With
.Line.Visible = msoFalse
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.