I have a code which is doing following:
Prompt to choose external workbook
Copying all the data from that wb
Pasting exactly 1:1 in main wb
Close and Save from .xlsm to .xlsx but with a name of my main wb
Sub CopySheetFromClosedWorkbook2() 'Prompt to choose your file in the chosen locatioon Dim dialogBox As FileDialog Dim FilePath As String Set dialogBox = Application.FileDialog(msoFileDialogOpen) Application.StatusBar = "Choose older PDS Form!" dialogBox.AllowMultiSelect = False dialogBox.Title = "Select a file" If dialogBox.Show = -1 Then FilePath = dialogBox.SelectedItems(1) 'If nothing selected then MsgBox Else MsgBox "No PDS Form selected!" Exit Sub End If 'Here are sheets defined which you are going to copy/paste (reference update) but to keep formatting. ''Sheets should be defined from right to left to have your sheets sorted from the beginning Dim shNames As Variant: shNames = Array("CH_or_Recipe_8", "CH_or_Recipe_7", "CH_or_Recipe_6", "CH_or_Recipe_5", "CH_or_Recipe_4", _ "CH_or_Recipe_3", "CH_or_Recipe_2", "CH_or_Recipe_1", "Customer Details", "Instructions") Dim tgt As Workbook: Set tgt = ThisWorkbook Application.ScreenUpdating = False Dim src As Workbook: Set src = Workbooks.Open(FilePath) Dim ws As Worksheet, rng As Range, i As Long For Each ws In src.Sheets If ws.Name Like "*[1-8]" Then ws.Name = "CH_or_Recipe_" & Right(ws.Name, 1) ElseIf ws.Name = "Customer_Details" Then ws.Name = "Customer Details" ElseIf ws.Name = "OIPT Plasmalab" Then ws.Name = "CH_or_Recipe_1" ElseIf ws.Name = "AMAT" Then ws.Name = "CH_or_Recipe_2" End If Next For i = 0 To UBound(shNames) On Error Resume Next Set ws = src.Sheets(shNames(i)) If Err.Number = 0 Then tgt.Worksheets(shNames(i)).Cells.Clear Set rng = ws.UsedRange rng.Copy tgt.Worksheets(shNames(i)).Range(rng.Address) End If Next i src.Close False Application.ScreenUpdating = True MsgBox "Copy&Paste successful!" End Sub Sub SaveNoMacro() Dim fn As String With ThisWorkbook fn = Replace(.FullName, ".xlsm", ".xlsx") Application.DisplayAlerts = False .SaveAs fn, FileFormat:=xlWorkbookDefault Application.DisplayAlerts = True End With MsgBox "Saved as " & fn End Sub
What I just need (if possible) is to save my wb in the same name as that external wb that I am taking data from and adding date/time at the end.
Example:
MainWB1.xlsm + ExternalWB1.xlsx >>> MainWB1.xlsx (This is now)
MainWB1.xlsm + ExternalWB1.xlsx >>> ExternalWB1_today().xlsx (This is what I wanna)