且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在word文档内的特定位置写入文本

更新时间:2023-10-09 12:49:28

您可以在要插入文本的位置设置书签。


然后,您可以使用

 doc.Bookmarks(" MyBookmark")。Range.Text ="我要添加的文本.... ; 




其中doc是Word.Document对象,MyBookmark是书签的名称。上面的行会破坏书签;如果你想要保存它看到
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm


Hi,

Anyone knows how to insert text at specific location in Word Document.

----------------------------------------------------------------------------Document Start--------------------------------------------------------------------------------------------

ABC

<The Text I want to Add.....>

XYZ

----------------------------------------------------------------------------Document End--------------------------------------------------------------------------------------------


Thanks, Parth

You could set a bookmark at the place where you want to insert the text.

You can then use

doc.Bookmarks("MyBookmark").Range.Text = "The Text I want to Add...."


where doc is a Word.Document object, and MyBookmark the name of the bookmark. The above line will destroy the bookmark; if you want to preserve it see http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm