Need help - macro to save file. Path and filename in cells

namuser

New Member
Joined
Jan 21, 2014
Messages
4
Hi,


I'm very new to this so I would really appreciate your help on this matter.


I have an excel database, column A with employee names and Column B with supervisor


name. I would like to build a macro which will save a specific file (called "template.xlsx")


in a folder named as Column B (supervisor name). The filename should be employee name


(Column A).


Values from column B are build as path_to_file/test/supervisor_name.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
you can save a file according to the values of cells easily.
this code will save IF the folders already exist if not youll need to add something that would check for the folder, if it does not exist will create it. if you google that or search here you will find a lot.

basically, you set a value for the supervisor and employee names and use those in your filepath when you save. this is just a little scratch to get you started, what i set the names to i am asuming you do not want to just use the first employee, but hopefully you can get that where you want.

Code:
Sub savefile()

    Dim SupName As String
    Dim EmpName As String
    
    SupName = Range("B2")
    EmpName = Range("A2")

    ActiveWorkbook.SaveAs Filename:= _
        "path_to_file\test\" & SupName & "\" & EmpName & ".xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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