Creating a filename from information in a cell in excel

wingspan99

New Member
Joined
Apr 30, 2018
Messages
3
Hi,

I am new to the forum, so I hope I am posting in the right place. What I am trying to do is set up a macro that saves the workbook to a specific filepath and creates part of the filename using the customer name in a specific cell.

The filepath would be: N:\\Dserv-FS\Customer Profiles\BRM Customers\Customer_Profile-"the contents of cell B6"

Thanks for any help you can give.

Mike
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I would do something that looks like this:

Code:
Sub saveTest()

Dim directory As String
directory = "N:\\Dserv-FS\Customer Profiles\BRM Customers\"

Dim fileName As String
fileName = "Customer_Profile-" & ActiveSheet.Range("B6").value

ActiveWorkbook.SaveCopyAs directory & fileName

End Sub

As far as application, you could put a button on the page, you could assign a hotkey to this macro, you could run this macro manually (F5) whenever you want to save... There's a lot of ways to trigger this, but you have to choose one.

Just be careful: I used "ActiveSheet" in this code, so it requires you to be looking at the sheet containing the "B6" customer profile. If you wanted to save from another sheet, you would need to modify the code to reflect that change.
 
Upvote 0
That's great. The only thing is that it isn't saving as an excel workbook.

Oh you right, I forgot the file extension, see the edit below in red:

Code:
Sub saveTest()

Dim directory As String
directory = "N:\\Dserv-FS\Customer Profiles\BRM Customers\"

Dim fileName As String
fileName = "Customer_Profile-" & ActiveSheet.Range("B6").value[COLOR=#ff0000] & ".xlsm"
[/COLOR]
ActiveWorkbook.SaveCopyAs directory & filename

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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