Save file in specific file with specific file name based on cell values

josh1981

New Member
Joined
Jul 8, 2012
Messages
25
Hi. Can someone please help me with a macro that will 'save as' a file in a folder based on F10 with a file name based on F9

as an example:
F10 cell value is 08 (value in cell is a formula)
F9 cell value is RTM CG-2 050812 (value in cell is a formula)
The directory is C:\My Dropbox\Archive\

so I would like the file directory will end up as C:\My Dropbox\Archive\08\RTM CG-2 050812.xlsm

Thanks for you help.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How's this?

Code:
Sub Macro1()
On Error GoTo ErrorHandler
    ChDir "C:\My Dropbox\Archive\" & CStr([F10])
    ActiveWorkbook.SaveAs "C:\My Dropbox\Archive\" & CStr([F10]) & "\" & CStr([F9]) & ".xlsm", 52
Exit Sub
ErrorHandler
    MkDir "C:\My Dropbox\Archive\" & CStr([F10])
    Resume Next
End Sub
 
Upvote 0
Thanks cstimart.
I get a compile error: Sub or Function not defined
with ErrorHandler highlighted
 
Upvote 0
Hi, josh1981,

the GoTo-address must be fllowed by an : like this:
Code:
ErrorHandler:
    MkDir "C:\My Dropbox\Archive\" & CStr([F10])
    Resume Next
Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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