编写一个程序调用过excel表用于打印预览或打印后,如果不退出程序,无法打开其他的excel文件,请教是怎么回事?怎么解决?

解决方案 »

  1.   

    Excel进程没有关闭,对象没有被释放
    你在进行完操作的时候,添加语句
    xlApp.Quit
    Set xlApp = Nothing其中xlApp是你声明的Excel.Application对象
      

  2.   

    进程我已经关了,我的意思是在没有退出程序,打开其他的excel文件就很困难,要么失去反应,要么打不开
      

  3.   

    呵呵,那你可能是没有释放对Excel的控制权,你是在什么地方释放Excel对象的?又是在什么时候打开Excel文件?
      

  4.   

    打印完或预览完就释放,打印或预览时,我打开开其他execl文件或,打印完释放才打开其他
    execl文件,就出现这样的问题
      

  5.   

    我也遇到相同问题!
    用xlApp.Quit
    无法在程序结束是退出EXCEL
      

  6.   

    各位,能不能给我一个使用excel的实例呀?
    我的email是[email protected]
      

  7.   

    下面给出一个实例:     首先建立一个窗体(FORM1)在窗体中加入一个DATA控件和一按钮,     引用Microsoft Excel类型库:     从"工程"菜单中选择"引用"栏;     选择Microsoft Excel 9.0 Object Library;     选择"确定"。     然后在FORM的LOAD事件中加入:     Private Sub Form_Load()
         '数据库及表可以另选,本文以Nwind.mdb为例
        Data1.DatabaseName = "C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb"
        Data1.RecordSource = "Customers"
        Data1.Refresh
        End Sub
        在按钮的CLICK事件中加入     Private Sub Command1_Click()
        Dim Irow, Icol As Integer
        Dim Irowcount, Icolcount As Integer
        Dim Fieldlen() '存字段长度值
        Dim xlApp As Excel.Application
        Dim xlBook As Excel.Workbook
        Dim xlSheet As Excel.Worksheet
        Set xlApp = CreateObject("Excel.Application")
        Set xlBook = xlApp.Workbooks.Add
        Set xlSheet = xlBook.Worksheets(1)
        With Data1.Recordset
        .MoveLast
        If .RecordCount < 1 Then
        MsgBox ("Error 没有记录!")
        Exit Sub
        End If
        Irowcount = .RecordCount '记录总数
        Icolcount = .Fields.Count '字段总数
        ReDim Fieldlen(Icolcount)
        .MoveFirst
        For Irow = 1 To Irowcount + 1
        For Icol = 1 To Icolcount
        Select Case Irow
        Case 1 '在Excel中的第一行加标题
        xlSheet.Cells(Irow, Icol).Value = .Fields(Icol - 1).Name
        Case 2 '将数组FIELDLEN()存为第一条记录的字段长
        If IsNull(.Fields(Icol - 1)) = True Then
        Fieldlen(Icol) = LenB(.Fields(Icol - 1).Name)
        '如果字段值为NULL,则将数组Filelen(Icol)的值设为标题名的宽度
        Else
        Fieldlen(Icol) = LenB(.Fields(Icol - 1))
        End If
        xlSheet.Columns(Icol).ColumnWidth = Fieldlen(Icol)
        'Excel列宽等于字段长
        xlSheet.Cells(Irow, Icol).Value = .Fields(Icol - 1)
        '向Excel的CellS中写入字段值
        Case Else
        Fieldlen1 = LenB(.Fields(Icol - 1))
        If Fieldlen(Icol) < Fieldlen1 Then
        xlSheet.Columns(Icol).ColumnWidth = Fieldlen1
        '表格列宽等于较长字段长
        Fieldlen(Icol) = Fieldlen1
        '数组Fieldlen(Icol)中存放最大字段长度值
        Else
        xlSheet.Columns(Icol).ColumnWidth = Fieldlen(Icol)
        End If
        xlSheet.Cells(Irow, Icol).Value = .Fields(Icol - 1)
        End Select
        Next
        If Irow <> 1 Then
        If Not .EOF Then .MoveNext
        End If
        Next
        With xlSheet
        .Range(.Cells(1, 1), .Cells(1, Icol - 1)).Font.Name = "黑体"
        '设标题为黑体字
        .Range(.Cells(1, 1), .Cells(1, Icol - 1)).Font.Bold = True
        '标题字体加粗
        .Range(.Cells(1, 1), .Cells(Irow, Icol - 1)).Borders.LineStyle = xlContinuous
        '设表格边框样式
        End With
        xlApp.Visible = True '显示表格
        xlBook.Save '保存
        Set xlApp = Nothing '交还控制给Excel
        End With
        End Sub