2024-10-13 12:27:46
别那么费事,
直接用 richbox 的 save方法把内容存放在一个临时的 rtf文件
RichTextBox1.SaveFile("e:\temp.rtf") '因为word是可以直接打开rtf文件的
然后用 Documents打开这个临时对象
Documents.Open ("e:\temp.rtf")
最后再另存为 word文件
ActiveDocument.SaveAs ("newname.doc",100, False, "", True, "",False, False,False, False, False)
'注意第二个参数是100 表示doc格式
完整代码如下:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim doc As Object, docword As Object
RichTextBox1.SaveFile("e:\1.rtf")
Doc = CreateObject("Word.Application")
DocWord = doc.Documents.Open("e:\1.rtf")
doc.ActiveDocument.SaveAs("newname.doc", 100, False, "", True, "", False, False, False, False, False)
doc.quit()
doc = Nothing
docword = Nothing
End Sub
那能不能将这个RTF打开后,添加到现有的WORD最后?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim doc As Object, docword As Object
RichTextBox1.SaveFile("e:\1.rtf")
doc = CreateObject("Word.Application")
docword = doc.Documents.Open("e:\newname.doc") '打开要向那个文件添加
doc.Selection.EndKey(6) '跳转到结尾
doc.Selection.InsertFile("e:\1.rtf", "", False, False, False) '插入保存的内容
doc.ActiveDocument.SaveAs("e:\newname.doc", 100, False, "", True, "", False, False, False, False, False)
doc.quit()
doc = Nothing
docword = Nothing
End Sub