关闭是要不就是出现"Microsoft Excel for Windows 遇到问题需要关闭。我们对此引起的不便表示抱歉。"错误要不就是"指令饮用的内存,该内存不能为"read"."的错误!Dim pblConn As New ADODB.Connection
Dim MyRecord As New ADODB.Recordset
Dim TestNumber As String
Public WithEvents xlapp As Excel.Application
Public xlBook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Dim FileName As StringPrivate Sub Form_Load()
TestNumber = pblTestNumber
Call DisableX(frmStone33)
pblConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=WlServer;Data Source=" & dbsName & ";Persist Security Info=False"
MyRecord.Open "select 文件路径 from sysTest_Number_Manage where [试验序号]='" & TestNumber & "'", pblConn, adOpenKeyset, adLockOptimistic
   If Not MyRecord.EOF Then
       FileName = MyRecord!文件路径
   Else
       FileName = wlPath & "\data\excel\aa.xls"
   End If
Set xlapp = CreateObject("Excel.Application")
   hWndWordApp = FindWindow("XLMAIN", xlapp.Caption)
Set xlBook = xlapp.Workbooks.Open(FileName)
'Set xlSheet = xlBook.Worksheets("Sheet1")
'xlSheet.Activate '激活工作表
.FindKey(BuildKeyCode(Arg1:=wdKeyControl, Arg2:=wdKeyS)).Disable
'    xlBook.Application.OnKey "^{C}", " "    --想屏蔽excel中的ctrl+C的快捷键却不好用
'    Application.OnKey "^{v}", " "
   If Not MyRecord.EOF Then
   xlBook.Application.CommandBars("Standard").Controls(3).Enabled = True
   Else
   xlBook.Application.CommandBars("Standard").Controls(3).Enabled = False
   End If
MyRecord.Close
Set MyRecord = Nothing
pblConn.Close
Set pblConn = Nothing
xlBook.Application.CommandBars("Standard").Controls(1).Enabled = False
xlBook.Application.CommandBars("Standard").Controls(2).Enabled = False
xlBook.Application.CommandBars("Standard").Controls(8).Enabled = False
xlBook.Application.CommandBars("Standard").Controls(9).Enabled = False
xlBook.Application.CommandBars("Standard").Controls(10).Enabled = False
xlBook.Application.CommandBars("Standard").Controls(11).Enabled = False
xlapp.Visible = True
  Dim lStyle As Long
    Dim tR As RECT
    GetWindowRect hWndWordApp, tR
    If hWndWordApp <> 0 Then
        lStyle = GetWindowLong(hWndWordApp, GWL_STYLE)
        If lStyle Then
            lStyle = lStyle And Not WS_SYSMENU
            lStyle = lStyle And Not WS_MAXIMIZEBOX
            lStyle = lStyle And Not WS_MINIMIZEBOX
            lStyle = lStyle And Not WS_CAPTION
          SetWindowLong hWndWordApp, GWL_STYLE, lStyle
         'SetWindowPos Hwndwordapp, 0, 0, 0, 1500, tR.Bottom - tR.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
           ShowWindow hWndWordApp, SW_SHOW
        Else
            MsgBox "出错,请重新打开"
        End If
    Else
        MsgBox "出错,请重新打开"
    End If
 Call SetParent(hWndWordApp, frmStone33.hwnd)
 xlBook.Application.CommandBars("Worksheet Menu Bar").Enabled = False
End SubPrivate Sub mnuBack_Click()
 Dim intResponse As Integer
    Dim isexit As Integer
    If xlBook.Saved = False Then
     isexit = MsgBox("您是否要保存文件!", vbYesNoCancel + vbQuestion, "信息提示")
     If isexit = vbYes Then
        b = wlPath & "\data\excel\" & TestNumber & ".xls"
        xlBook.Application.CommandBars("Worksheet Menu Bar").Enabled = True
        xlBook.Application.CommandBars("Standard").Reset
       xlBook.Application.CommandBars("Standard").Enabled = True
        xlBook.Application.ActiveWorkbook.SaveAs (b)
        Call sysTableSave(Me, "0070303", b, TestNumber)
        'xlSheet.Application.Quit
        xlBook.Application.Quit
        xlapp.Quit
        Set xlapp = Nothing
         Unload Me
    Else
      If isexit = vbNo Then
       xlBook.Application.CommandBars("Worksheet Menu Bar").Enabled = True
       xlBook.Application.CommandBars("Standard").Reset
       xlBook.Application.CommandBars("Standard").Enabled = True
        'xlBook.Close (False)
        xlBook.Application.DisplayAlerts = False
        xlBook.Close
        xlapp.Quit
        Set xlapp = Nothing
         Unload Me
      Else
       Cancel = True
      End If
    End If
  Else
   xlBook.Application.CommandBars("Worksheet Menu Bar").Enabled = True
   xlBook.Application.CommandBars("Standard").Reset
   xlBook.Application.CommandBars("Standard").Enabled = True
'    xlSheet.Application.Quit
    xlBook.Application.Quit
    xlapp.Quit
    Set xlapp = Nothing
    Unload Me
 End If
End Sub