本文介绍了如何在所需位置的现有.docx文件中添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打开一个现有的.docx文件,并在第二段中插入一些文本.
I want to open an existing .docx file and insert some text in second paragraph.
Private Sub insertText()
Dim WordApp As New Microsoft.Office.Interop.Word.Application
Dim aDoc As Microsoft.Office.Interop.Word.Document = WordApp.Documents.Open("C:\File1.docx")
Dim RNG As Microsoft.Office.Interop.Word.Range()
end sub
现在我应该写些什么来在第二段中插入一些文字?任何帮助将不胜感激.预先感谢.
Now what should I write to insert some text in second para ??Any help will be greatly appreciated. Thanks in advance.
推荐答案
是的.我得到了答案.
Private Sub insertText()
Dim WordApp As New Microsoft.Office.Interop.Word.Application
Dim aDoc As Microsoft.Office.Interop.Word.Document = WordApp.Documents.Open("C:\File1.docx")
Dim RNG As Microsoft.Office.Interop.Word.Range()
Dim PARA As Microsoft.Office.Interop.Word.Paragraph = aDoc.Paragraphs.Add()
If aDoc.Paragraphs.Count > 1 Then
aDoc.Paragraphs(2).Range.InsertParagraphBefore()
aDoc.Paragraphs(2).Range.Text = "Hello World"
end if
end sub
此代码首先在第二段上方添加一个新段,然后将Hello World插入到新创建的第二段中.干杯....
This code first a new para above second para and inserts Hello World in newly created second para.Cheers....
这篇关于如何在所需位置的现有.docx文件中添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!