rodrigo_m_almeida
New Member
- Joined
- Jan 13, 2022
- Messages
- 42
- Office Version
- 2021
- Platform
- Windows
Does anyone have any ideas ?
How to do this
I'm trying with
If Worksheets have the same name and different extensions,
open files copy all XLS content to paste and save in CSV in the last blank line...
My Problem...
I'm not able to copy and paste and not have idea how to work with the same names workbooks
How to do this
I'm trying with
VBA Code:
Public Sub ABC123()
' Optimize
Application.ScreenUpdating = False: Application.DisplayAlerts = False
' Declare Variables
Dim xPathName As Variant, xFileName01, xFileName02 As String, xOldWB, xNewWB As Workbook
' Browse File
Set FileDialog = Application.FileDialog(msoFileDialogFolderPicker)
FileDialog.Title = "Select Folder :"
If FileDialog.Show = -1 Then
xPathName = FileDialog.SelectedItems(1)
Else
Exit Sub
End If
If Right(xPathName, 1) <> "\" Then xPathName = xPathName + "\"
' Search Extension
xFileName01 = Dir(xPathName & "*.xls")
xFileName02 = Dir(xPathName & "*.csv")
Do While xFileName01 <> ""
' Open File 01 (XLS)
Workbooks.Open Filename:=xPathName & xFileName01
Set xOldWB = ActiveWorkbook
' Open File 02 (CSV)
Workbooks.Open Filename:=xPathName & xFileName02, Delimiter:=";", Local:=True
Set xNewWB = ActiveWorkbook
' Copy And Paste
xOldWB.Range("A" & Rows.Count).End(xlUp).Row.Copy
xNewWB.Range("A" & Rows.Count).End(xlUp)(2).Row.PasteSpecial (xlPasteValues)
' Save File
xNewWB.SaveAs Filename:=xPathName & xFileName01, FileFormat:=xlCSV, Local:=True
' Close File
xOldWB.Close
xNewWB.Close
' New Search
xFileName01 = Dir
Loop
' Optimize
Application.ScreenUpdating = True: Application.DisplayAlerts = True
End Sub
If Worksheets have the same name and different extensions,
open files copy all XLS content to paste and save in CSV in the last blank line...
My Problem...
I'm not able to copy and paste and not have idea how to work with the same names workbooks