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.
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

mtharnden

Board Regular
Joined
Aug 17, 2011
Messages
114
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,304
Messages
5,600,862
Members
414,409
Latest member
FloordAlex

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
Top