VBA: Insert File Name into a Column after Merging Multiple Files and Code "Yes" to Pop Up
Hello,
I am self-taught in VBA so my knowledge is limited. I figured out how to merge multiple files together and insert a column, but am unsure how to make Column A be the file name (I need this to be an identifier for the data).
I also receive a pop up that says "A formula or sheet you want to move or copy contains the name '...', which already exists on the destination worksheet. Do you want to use this version name?" How do I code this to select "Yes" each time?
What I have is below:
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
Set dirObj = mergeObj.Getfolder("C:\Users\kksmith\Documents\Projection")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
Range("A26:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("A65536").End(xlUp).Offset(1, 1).PasteSpecial
Application.CutCopyMode = False
bookList.Close savechanges:=False
Next
End Sub
Thanks!
Recent comments
5 years 42 weeks ago
6 years 28 weeks ago
6 years 40 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 49 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago