VBA to save Workbook, name defined in cell

xangetzu

New Member
Joined
Oct 23, 2017
Messages
3
Greetings.
I have a series of workbooks I navigate between using references to cells and built in VBA commands for file directory and such. In particular I have a Template document which I use to create new workbooks for a particular project, who's title changes as I build a particular report. When I use my macro to navigate back to my home file, opening that is easy but for closing the current workbook I am in, I have to manually edit the script in VBA to the file name. By default it is called Template.xlsb as that is the template file's name. Is there a way to make that string a reference to a cell like I use in opening workbooks. I have tried using the same method but I return an out of range error.

Sample code.
Sub Open_Launcher()
'
' Open Launcher back up
'
'
'
Sheets("Navigation").Select
Workbooks.Open Filename:=Range("B3").Value & "\Launcher.xlsb"
Workbooks("Launcher.xlsb").Sheets("Home").Activate
Workbooks("Template.xlsb").Close SaveChanges:=True
End Sub​


I have tried changing the last line to Workbooks.Close Filename:=Range("B6").Value (This cell contains the file name with extension) and I get a return that is out of range or there are the wrong number of arguments. Thinking that I may need to include some text, I took the extension out, and changed it to Workbooks.Close Filename:=Range("B6").Value & ".xlsb" but got the same error.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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