Home > Software engineering >  [for] multiple Excel file to a folder (each file has more than one sheet and is not the same as the
[for] multiple Excel file to a folder (each file has more than one sheet and is not the same as the

Time:10-02

I want to achieve the goal of a folder under multiple Excel file (each file has more than one sheet and is not the same as the name) is copied to the template, and then save to the specified folder (save Excel name like the name of the original Excel), form a loop, now I can implement a single file, but can't cycle, the following is the code I wrote cycle, now found two questions 1, two file cannot be converted, 2, and each file has more than one sheet and is not the same as the name, also show errors cannot be achieved, sheet name, because there is no success don't know if there are no other problems, please correct me a great god, thank you,

Sub keylingc3 ()
Dim Path As String
Dim the File As a String
Dim wb As Workbook
Application. ScreenUpdating=False 'frozen screen
Path="C: \ \ Users \ \ Desktop \ 13731 budget" 'the target folder Path assigned to variables, the Path can be change
The File=Dir (Path & amp; "*. XLSX") 'a search path in the excel file, here is it. XLSX. XLS, can change our
The Do While the File & lt;> "" 'when a file in the specified path circulation
The Set wb=Workbooks. Open (Path & amp; The File) '
conform to the requirements of the open FileCall Workbooks. Open (" C: \ Users \ \ Desktop \ 13731 new folder template - copy - copy. (2) \ XLSX ") 'Open the template
Windows (" & amp; The File & amp; "). Activate 'point open to copy files
Sheets (Array (" table ", "table 2", "table top", "table 3 c", "table 4 (domestic material list)", "table 4 (equipment)", "table 5")). Select 'call you on the other side of the specific operation of the macro for each excel file can be written directly in the macro
Sheets (" table "). Activate 'move all sheet
Sheets (Array (" table ", "table 2", "table top", "table 3 c", "table 4 (domestic material list)", "table 4 (equipment)", "table 5)"). The Move Before:=_
Workbooks (" template - copy - copy. XLSX "). The Sheets (1) 'move to the template file
Sheets (" Sheet1 "). Select
ActiveWindow. SelectedSheets. Delete 'Delete redundant Sheet template files
Sheets (" table "). Select
ActiveWorkbook. SaveAs Filename:=_
"C: \ Users \ \ Desktop \ new folder (3) 13731 " & amp; The File & amp; "", FileFormat:=_
XlOpenXMLWorkbook CreateBackup:=False
Application. The WindowState=xlNormal 'save name for the original file name
ActiveWindow. Close 'Close the file
File=Dir 'search for the next excel File
Loop
Application. ScreenUpdating=True 'thaw screen
End Sub

  •  Tags:  
  • VBA
  • Related