"VBA Research" find the names of all the files under the folder

Source: Internet
Author: User

Iamlaosong

 folder inside the image file is saved with a single scan, the file name is the mail number, now want to collect these mail numbers, because the volume is very large, it is not possible to intercept a single, only through the program implementation, assuming that the current worksheet B is placed in the folder of these image files, The following program can be used to tell the message number of these image files: 
Sub findname () Dim FS, F, F1, FC, Mydir MaxRow = Sheets ("Mail Number"). UsedRange.Rows.Count If maxrow >= 2 then Sheets ("Mail Number"). Rows ("2:" & MaxRow). Delete Shift:=xlup Lineno = [B65536]. End (Xlup).  Row ' number of rows, number of folders Row1 = 2 for num = 6 to Lineno ' from line 6th to store folder name Mydir = Thisworkbook.path & "\" & Cells (num, 2) ' folder name if Dir (Mydir, vbdirectory) <> vbnullstring Then ' Dir function can not only determine whether a folder exists, You can also determine whether a file exists set fs = CreateObject ("Scripting.FileSystemObject") set F = fs. GetFolder (Mydir) ' Enter the directory you specified in parentheses Set FC = F.files for each F1 in FC Shee TS ("Mail number"). Cells (row1, 1) = Left (f1.name) Row1 = row1 + 1 Next cells (num, 3) = "Success" E LSE ' MsgBox Mydir & ' folder does not exist! ", vbOKOnly," Iamlaosong "Cells (num, 3) =" Failed "End If Next num MsgBox" Number of extracted mail numbers: "& Row1-2, vbOKOnly, "Iamlaosong" End Sub 


"VBA Research" find the names of all the files under the folder

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.