zoukankan      html  css  js  c++  java
  • 如何用VBA代码依次打开文件夹下的Excel文件

    'Check Public Function Check() As Variant On Error GoTo erlb      Dim StrDir As String    StrDir = ThisWorkbook.Worksheets("Path").Range("B2")     objfile = Dir(StrDir & "*.xlsx")    ThisWorkbook.Worksheets("Result").Activate      With ActiveSheet       .Range("A2:B400").Select       ' .Cells.Select        Selection.ClearContents        .Range("A1").Select  End With      Application.ScreenUpdating = False    Do While objfile <> ""      Workbooks.Open StrDir & "" & objfile          ' Workbooks(objfile).Activate      ActiveWorkbook.Worksheets("Sheet1").Activate           maxRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row

         iCnt = 0      startRow = 9           With ActiveSheet         For iRow = startRow To maxRow             If Trim(ActiveSheet.Cells(iRow, 1)) <> "" Then                If Trim(ActiveSheet.Cells(iRow, 2)) = "" Then                     iCnt = iCnt + 1                End If             Else                Exit For             End If         Next      End With           Workbooks(objfile).Activate           'Workbooks(objfile).Close          ActiveWorkbook.Close           With ThisWorkbook.Worksheets("結果")          resultmaxRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row          .Cells(resultmaxRow + 1, 1) = objfile          .Cells(resultmaxRow + 1, 2) = iCnt      End With           objfile = Dir        Loop     Application.ScreenUpdating = True      MsgBox "計算完了"      Exit Function   erlb:

      MsgBox Err.Number & Err.Description  End Function        

  • 相关阅读:
    MySQL--字符集参数
    MySQL--字符集基础
    Cassandra基础2
    Cassandra基础
    Cassandra -- Cassandra 3.0版本安装
    Cassandra Demo--Python操作cassandra
    MySQL--批量插入导致自增跳号问题
    MySQL Disk--SSD和HDD的性能
    MySQL Lock--并发插入导致的死锁
    TCL-视图
  • 原文地址:https://www.cnblogs.com/mochaMM/p/4764218.html
Copyright © 2011-2022 走看看