WORD应用的怪问题
Private Sub Command1_Click()
Dim myDoc As Document
Dim myRange As Range
Set myDoc = New Document
Set myDoc = Documents.Add
Set myRange = myDoc.Content
myDoc.SaveAs App.Path & "\Test.Doc"
With myRange
.Collapse wdCollapseEnd
.InsertAfter "标题"
.InsertParagraphAfter
.Font.Name = "黑体"
.Font.Size = 24
.Paragraphs(1).Alignment = wdAlignParagraphCenter
.Collapse Direction:=wdCollapseEnd
.InsertAfter "内容"
End With
myDoc.Close wdSaveChanges
End Sub
以上这段代码运行起来并没有什么问题,但是只能运行一次,运行第二次(同一次执行期间)时就会出现“远程服务器不存在或不能使用”的错误!
我自己试了一下,如果没有打开WORD,只要用了Close方法,再使用set Doc=new Documents.Add就会出错,如果打开了WORD就没有任何问题。在Delphi中也有类似情况。
我要问各位的是,怎样在不打开WORD的情况下,重复使用Add 和 Close ?