Opening workbooks and saving as using cell references

anichols

Board Regular
Joined
Mar 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
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:
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
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.
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!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top