VBA Copy multi CSV/Excel files from Folder to one WorkBook

MC01_

New Member
Joined
Dec 1, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Greetings, i hope you all are good.
After read lots a post in this Forum, I have find a VBA in this forum to copy files in .xmlx and other to do the same on .csv files to one single sheet.

Can it be possible the same VBA run it this two types of files? And copy them to a master WorkBook organize by the name of the folders?

In the case of . CSV files after the copy to the Master Workbook can it transform only the colluns in number to text.

I have a folder whit sub-folders and in that subfolders the files to merge (sometimes 1 unic file but at the end of each moth they are 20 files)


The post i read and use is this : https://www.mrexcel.com/board/threads/copy-specific-files-from-folder-and-sub-folder.1147092/

Can anybody help me please.
 

Attachments

  • Folder.PNG
    Folder.PNG
    3.6 KB · Views: 18
  • Files.PNG
    Files.PNG
    1.9 KB · Views: 19
  • Test final.PNG
    Test final.PNG
    4.9 KB · Views: 19

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Who can I use this for my needs
From this VBA i just merge only one file at time

Sub test()
Dim Wb1 As Workbook, Wb2 As WorkBook, Wb3 As Workbook
Dim MainBook As Workbook

'Open All workbooks first:
Set Wb1 = Workbooks.Open(" book1.xlsx")
Set Wb2 = Workbooks.Open(" book2.xlsx")
Set Wb3 = Workbooks.Open(" book3.xlsx")
Set MainBook = Workbooks.Open(" Masterbook.xlsx")

'Now, copy what you want from wb1:
wb1.Sheets("Sheet1").Cells.Copy
'Now, paste to Main worksheet:
MainBook.Sheets("Sheet1").Range("A1").PasteSpecial

'Now, copy what you want from wb2:
wb2.Sheets("Sheet1").Cells.Copy
'Now, paste to Main worksheet:
MainBook.Sheets("Sheet2").Range("A1").PasteSpecial

'Now, copy what you want from wb3:
wb3.Sheets("Sheet1").Cells.Copy
'Now, paste to Main worksheet:
MainBook.Sheets("Sheet3").Range("A1").PasteSpecial

'Close Wb's:
Wb1.Close
Wb2.Close
Wb3.Close
MainBook.Save
MainBook.Close

End Sub

Please Help
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top