I have a set of workbooks that contain data that needs to be copied to a new version of the workbook. I found a macro that I added to the new workbook that will open the open file dialogue to allow you to select a file. It then opens the file, copies specific cells to the new workbook and then closes the workbook.
Sub CopyDataToNewWB()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Copy Data", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A5:o199").Copy
ThisWorkbook.Worksheets("Calculator").Range("A5").PasteSpecial xlPasteValues
OpenBook.Sheets(1).Range("AO5:AR34").Copy
ThisWorkbook.Worksheets("Calculator").Range("AO5").PasteSpecial xlPasteValues
OpenBook.Application.CutCopyMode = False
OpenBook.Close False
End If
Application.Goto Reference:=Worksheets("Calculator").Range("A5"), _
Scroll:=False
Application.ScreenUpdating = True
End Sub
I would like to get the filename of the old workbook that was opened and use it in a save-as function to save over top of the old file. I would like to keep the new file open so that I can repeat the process on subsequent files. Of course I will be working on a backup directory of the original files and not the originals themselves.
I have been searching for ways to do this and for code it incorporate but with my minimal knowledge of VBA, I struggle to figure out hoe to incorporate anything and make it all work. I appreciate everyone's help once again.