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        

  • 相关阅读:
    洛谷 P2048 [NOI2010]超级钢琴(优先队列,RMQ)
    洛谷P1074 靶形数独(跳舞链)
    洛谷P1337 [JSOI2004]平衡点 / 吊打XXX(模拟退火)
    洛谷P4003 无限之环(费用流)
    洛谷P3264 [JLOI2015]管道连接(斯坦纳树)
    洛谷P3190 [HNOI2007]神奇游乐园(插头dp)
    洛谷P3272 [SCOI2011]地板(插头dp)
    常用的端口配置
    Win7+Eclipse+Hadoop2.6.4开发环境搭建
    Windows10+eclipse+hadoop2.7.1环境配置+wordcount-折腾笔记
  • 原文地址:https://www.cnblogs.com/mochaMM/p/4764218.html
Copyright © 2011-2022 走看看