• 如何用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        

  • 相关阅读:
    组合总和
    子集Ⅱ
    子集
    全排列Ⅱ
    全排列
    填充下一个结点下一个Next结点
    把二叉树转化成累加树
    二叉树的左叶子之和
    高速C/C++编译工具ccache
    【转载】如何用U盘制作Ubuntu启动盘
  • 原文地址:https://www.cnblogs.com/mochaMM/p/4764218.html
Copyright © 2020-2023  润新知