Home > Software engineering > Vb access to several hundred all excel sheet folder name efficiency problem
Vb access to several hundred all excel sheet folder name efficiency problem
Time:10-07
Folder there are hundreds of excel, each with different number of sheet, how to get all the sheet name, form it is best to excel + sheet, I now use is To obtain all excel the name of the first (a) very quickly, and then loop all excel respectively carry out the following code Dim XlApp As New Excel. Application Dim XLWorkBook As New Excel. The Workbook The Set XLWorkBook=XlApp. Workbooks. Open (App) Path & amp; "\ 1. XLS") For I=1 To XLWorkBook. Worksheets. Count List1. AddItem XLWorkBook. Sheets (I). The Name Next I XlApp. Quit This code is actually still open the excel, first take the sheet name again after closing, problems come out, hundreds of excel to perform two or three minutes, this can't be sure, do you have any faster method, can take to the folder name all all excel sheet, thank you
CodePudding user response:
If it is me, what I did,
CodePudding user response:
But Excel. Application objects created only once, Then is kept open and close the file,
CodePudding user response:
Try to use the database efficiency way of reading may be better...
CodePudding user response:
Use the method of external database should be much quicker,
In the first place in a connection object cn will Excel file as an external database open:
Cn. The Open ". The Provider=Microsoft Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ 1. XLS; Extended Properties=8.0 "" Excel; HDR=Yes; IMEX=1 ", " " Then, in the open recordset object Schema record:
Set the rs=cnn1. OpenSchema (adSchemaTables)
The recordset TABLE_NAME fields of each record is a name of the table, however, to use TABLE_TYPE field filtering system tables, to print a detailed look at to know,
CodePudding user response:
XLWorkBook. Close
Don't quit
CodePudding user response:
Thank you for your help
CodePudding user response:
Still can't solve
CodePudding user response:
Give it a try:
Dim XlApp As New Excel. Application Dim XLWorkBook As New Excel. The Workbook Dim fn as String Dim n As Long XlApp. Visible=False For n=1 to 100 Fn=App. Path & amp; "" + CStr (n) + ". XLS " The Set XLWorkBook=XlApp. Workbooks. Open (fn) For each in XLWorkBook. Worksheet in XLWorkBook. Sheets The debug. Print fn;" + "; XLWorkBook. Sheet. Name Next The Set XLWorkBook=Nothing XlApp. Close The next n
CodePudding user response:
For each in XLWorkBook. Worksheet in XLWorkBook. Sheets Should be changed to For each XLWorkBook. Worksheet in XLWorkBook. Sheets
CodePudding user response:
Upstairs method is also open to close again, certainly not soon