如何在特定位置的Word文档中添加文本?
问题描述:
如何写到Word文档中的特定位置,例如,第5行,字符50?我搜索了几个小时,但找不到解决方案.
How do I write to a specific position in a Word document, for example, line 5, character 50? I have searched for a couple of hours, but couldn't find a solution.
我正在使用Microsoft.Office.Interop.Word
答
如果您对更简单的句子而不是行感到满意:
If you are content with the more simple sentence, rather than lines:
ActiveDocument.Sentences(1).Characters(5).Select
Selection.Collapse
Selection.InsertBefore "added "
VBA中的五个段落和50个空格
Five paragraphs and 50 spaces in VBA
Selection.Text = String(5, vbCrLf)
Selection.Collapse wdCollapseEnd
Selection.Text = String(50, " ")
但是,对于特定位置,我希望使用文本框:
However, for a particular position, I would prefer a textbox:
Set sh = doc.Shapes.AddTextbox(1, 10, 344, 575, 80)
sh.Name = "Course1"
具有一些属性:
sh.Fill.Visible = False
sh.Line.Visible = False
sh.TextFrame.MarginLeft = 0#
sh.TextFrame.MarginRight = 0#
sh.TextFrame.MarginTop = 0#
sh.TextFrame.MarginBottom = 0#