Thx for the kindly help from Shownic. But sorry that I can't understand what it meant by using "appword = nothing".
Here is what I have modified:
Private AppWord As Word.Application
Private Sub Command1_Click()
On Error Resume Next
Set AppWord = GetObject(, "Word.Application")
  If Err.Number <> 0 Then
    Set AppWord = New Word.Application
  End If
On Error GoTo ErrorHandler
With AppWord
    .Visible = True
    .WindowState = wdWindowStateMaximize
    .Documents.Add
    .Selection.Tables.Add Range:=.Selection.Range, _
       NumRows:=3, _
       numColumns:=3
    .Selection.Tables(1).Cell(2, 2).Select
    .Selection.Cells(1).SetWidth _
       ColumnWidth:=CentimetersToPoints(12), _
       rulerstyle:=wdAdjustNone
  End With
    Set AppWord = Nothing
  Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub
But the error that I mentioned before is still here. Could you kindly to help me to solve it again?
arrow
arrow
    全站熱搜

    vbqa 發表在 痞客邦 留言(0) 人氣()