标题:关于EXCEL释放控制的问题
只看楼主
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
结帖率:78.95%
已结贴  问题点数:20 回复次数:2 
关于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
搜索更多相关主题的帖子: EXCEL Dim If End For 
2017-12-08 15:16
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
得分:20 
不是execl问题,是你没给cpu时间响应。

再内循环中i,kk中增加doevents语句就可以。

2017-12-11 22:19
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
解决了
释放控制的问题,是因为检测到空白单元格后直接跳出了sub,并没有执行释放

空格的问题,是因为检测相同编码时,没有等检测循环结束就执行添加操作
2017-12-13 11:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-483212-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087255 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved