关于EXCEL释放控制的问题
两个问题1、为什么EXCEL释放不了控制,怎么解决?
2、为什么导EXCEL进去的时候会有间隔呢
代码如下
Private Sub Command1_Click()
Dim i As Integer
Dim ss As String
Dim kk As Integer
Dim jj As Integer
Dim cho As Boolean
Dim xlapp As Excel.Application 'Excel对象
Dim xlbook As Excel.Workbook '工作簿
Dim xlsheet As Excel.Worksheet '工作表
'On Error GoTo userCanceled
With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
.Filter = "excel文件(*.xls)|*.xls|excel文件(*.xlsx)|*.xlsx"
.ShowOpen
'ShellExecute Me.hWnd, "open", .FileName, "", "", SW_HIDE
'Dim WinWnd As Long
'WinWnd = FindWindow(vbNullString, "Microsoft Excel - " & .FileTitle)
'If WinWnd <> 0 Then
'ShowWindow WinWnd, SW_HIDE
'End If
End With
ss = CommonDialog1.FileName
Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Open(ss)
xlapp.Visible = False
Set xlsheet = xlbook.Worksheets(1)
For j = 1 To 100
For i = 1 To 9
If xlsheet.Cells(j + 1, i + 1) = "" Then
MsgBox "表格中第" & j + 1 & "行" & "第" & i + 1 & "列存在空白单元格,录入已中止!", vbInformation
Exit Sub
End If
Next
jj = ListView1.ListItems.Count
If jj > 0 Then
For kk = 1 To jj
If xlsheet.Cells(j + 1, 4) = ListView1.ListItems(kk).SubItems(3) Then
If MsgBox("表格中第" & j + 1 & "行的物料编码列表中已存在,是否确认覆盖?", vbCritical + vbYesNo, "提示") = vbNo Then
MsgBox "录入已中止,可调整编码后重新导入!"
Exit Sub
Else
For i = 1 To 9
ListView1.ListItems(kk).SubItems(i) = xlsheet.Cells(j + 1, i + 1) & ""
Next
Exit For
End If
Else
ListView1.ListItems.Add , , jj + 1
For i = 1 To 9
ListView1.ListItems(jj + 1).SubItems(i) = xlsheet.Cells(j + 1, i + 1) & ""
Next
End If
Next
Else
ListView1.ListItems.Add , , 1
For i = 1 To 9
ListView1.ListItems(1).SubItems(i) = xlsheet.Cells(2, i + 1) & ""
Next
End If
Next
xlbook.Close
xlapp.Quit
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
'userCanceled:
End Sub