请先看代码,当点击Command1按钮的时候打开word程序和空白文档,当关闭WORD后再点击Command1时就会报错:“实时错误'462':远程服务器不存在或不能使用”,但如没有那个with wDoc块就不会报错,但我需要用with wDoc中的语句,请问哪位高手能解决,或告诉我是什么原因也行,谢谢 !
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim wSel As Word.Selection
Dim wTab As Word.TablePrivate Sub Command1_Click()    Set wApp = New Word.Application
    
    wApp.Visible = True
    
    Set wDoc = wApp.Documents.Add
    
    Set wSel = wApp.Selection
    
    With wDoc.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientLandscape
        .TopMargin = CentimetersToPoints(1)
    End With
    
    Exit Sub

解决方案 »

  1.   

    application.quit
    set wdoc=nothing
    这样就可能解决问题
      

  2.   

    在结束command的事件时一定要先结束Word.
    要不然.程序会长驻内存.
    application.quit
    set wdoc=nothing
      

  3.   

    Set WodApp = CreateObject("Word.Application")
                        With WodApp
                              .Visible = True
                              .Documents.Add
                               .......................
                              .Documents.Save
                              .Quit
                        End With