Macros! How to save file in location in cell and name file as cell!! Help

GoingmadwithExcel

New Member
Joined
Aug 20, 2015
Messages
4
Hello,

I am far from an expert in excel and I desperately need help with Macros.

I have a date in cell B4 and a name in Cell C1.
I have set up folders in my location path with all the dates that I want to use.

How do I use a Macro to save the file like below?

"W:\\Programme\Department Data\Documents\B4\C1.xml, "
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hello,

I am far from an expert in excel and I desperately need help with Macros.

I have a date in cell B4 and a name in Cell C1.
I have set up folders in my location path with all the dates that I want to use.

How do I use a Macro to save the file like below?

"W:\\Programme\Department Data\Documents\B4\C1.xml, "
Hi GoingmadwithExcel, welcome to the boards.

Here is how I did it based on your example data.

You will need a cell on your sheet somewhere that contains W:\Programme\Department Data\Documents. For sake of example I have made this A1 but you can put it anywhere so long as you reference it correctly.
You already have a cell with the date in B4
You already have a cell with the desired file name in C1

So long as all of the folder structures are already set up correctly the following macro would work to save a copy​ of your file:

Rich (BB code):
Sub SaveFile()
Application.ScreenUpdating = False
Dim sFile As String
sFile = Worksheets("Sheet1").Range("C1").Value & ".xml"
ActiveWorkbook.SaveCopyAs Filename:=Worksheets("Sheet1").Range("A1").Value & "\" & Worksheets("Sheet1").Range("B4").Value & "\" & sFile
MsgBox "Saved"
End Sub

The bits in bold can be amended to suit your data. The bold A1 is where I entered the filepath W:\Programme\Department Data\Documents (with no \ on the end). Finally I added a popup message box that just says "Saved" when completed, but this can either be removed of changed to say whatever you like.

Try this out on a copy of your original spreadsheet and see if it works.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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