Hello all,
I have a workbook that will open multiple workbook and edit the data before saving and closing them. I'm now needing to save a copy of the first workbook under a new name in a new file path before I make any changes. The file paths of all workbooks are changing everyday, and as such, I use cell references to capture the correct location. It's entirely possible that I am making this more difficult than need be, and if so, I would certainly appreciated be schooled in the art of simplified coding or "less is more"
To clarify:
My primary sheet "Monthly" is opened,
a macro will then open a sheet called "master" whose full file path and name is located in Sheet 1: B4. See below:
That works perfectly...
Next I am trying to save a copy of the "master" file I just opened to the full file path and name located in "Monthly" Sheet 1: B5. That's where I am struggling.
I have a workbook that will open multiple workbook and edit the data before saving and closing them. I'm now needing to save a copy of the first workbook under a new name in a new file path before I make any changes. The file paths of all workbooks are changing everyday, and as such, I use cell references to capture the correct location. It's entirely possible that I am making this more difficult than need be, and if so, I would certainly appreciated be schooled in the art of simplified coding or "less is more"
To clarify:
My primary sheet "Monthly" is opened,
a macro will then open a sheet called "master" whose full file path and name is located in Sheet 1: B4. See below:
VBA Code:
Option Explicit
Sub Master()
Dim wrkMyWorkBook As Workbook
If Dir(Sheets("Sheet1").Range("B4").Value, vbDirectory) = vbNullString Then
MsgBox "The full path of """ & Sheets("Sheet1").Range("B4").Value & """ doesn't exist!!"
Exit Sub
End If
On Error Resume Next 'Ignore any errors (i.e. if workbook is not open)
Set wrkMyWorkBook = Workbooks(Sheets("Sheet1").Range("B4").Value)
On Error GoTo 0 'Turn error reporting back on
'If the 'wrkMyWorkBook' variable is Nothing then the workbook is not open, therefore we'll...
If wrkMyWorkBook Is Nothing Then
'...open it
Set wrkMyWorkBook = Workbooks.Open(Filename:=Sheets("Sheet1").Range("B4").Value)
End If
End Sub
Next I am trying to save a copy of the "master" file I just opened to the full file path and name located in "Monthly" Sheet 1: B5. That's where I am struggling.
VBA Code:
Sub CR_LCA()
'XAB 3.12.21
Dim Lastrow As Long
Dim R As Long
Dim workbook_Name As Variant
Application.ScreenUpdating = False
Lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
workbook_Name = Excel.Workbooks("Monthly.xlsm").Sheets("Sheet1").Range("B5")
If workbook_Name <> False Then
ActiveWorkbook.SaveAs Filename:=workbook_Name
End If
Application.ScreenUpdating = True
'ActiveWorkbook.Save
'ActiveWorkbook.Close
End Sub
Once the code executes, I should just have the "Monthly" file, and the "New" file from B5.
Many thanks!