How to open an Excel file under a folder by using VBA code in turn

Source: Internet
Author: User

' Check public Function check () as Variant on Error GoTo erlb      dim strdir as String    st Rdir = 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 <> "" &nb sp;    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 ("results")          Resultmaxrow =. Usedrange.rows (. UsedRange.Rows.Count). Row         . Cells (Resultmaxrow + 1, 1) = objFILE         . Cells (Resultmaxrow + 1, 2) = icnt      End with           obj File = Dir        Loop     application.screenupdating = True      MsgBox "Finished"      exit Function   ERLB:

MsgBox Err.Number & Err.Description End Function

How to open an Excel file under a folder by using VBA code in turn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.