J Jodie Nov 2, 2009 #1 I would like to write a macro to save an excel file with the name being equal to the first 3 digits of cell A1. Can this be done?
I would like to write a macro to save an excel file with the name being equal to the first 3 digits of cell A1. Can this be done?
D Dave Peterson Nov 2, 2009 #2 With activeworkbook .saveas filename:="C:\somepath\" _ & left(.worksheets("Somesheetname").range("a1").value, 3) & ".xls", _ fileformat:=xlworkbooknormal end with If the value in A1 of that sheet is a number, you may want: & left(format(.worksheets(somesheetname").range("a1").value, "000"), 3) & ... so 1 is saved as 001.xls
With activeworkbook .saveas filename:="C:\somepath\" _ & left(.worksheets("Somesheetname").range("a1").value, 3) & ".xls", _ fileformat:=xlworkbooknormal end with If the value in A1 of that sheet is a number, you may want: & left(format(.worksheets(somesheetname").range("a1").value, "000"), 3) & ... so 1 is saved as 001.xls
M Mike H Nov 2, 2009 #3 Hi, Try this ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls" Mike
G Gord Dibben Nov 2, 2009 #5 Did you type the code into your module? Maybe you missed a parens? Copy the line and it works. Gord Dibben MS Excel MVP
Did you type the code into your module? Maybe you missed a parens? Copy the line and it works. Gord Dibben MS Excel MVP
M Merlynsdad Nov 2, 2009 #6 Check for typos; it just worked for me. I put 123456 in A1 and now have 123.xls.
J Jodie Nov 2, 2009 #7 Would it have something to do with the fact that I am starting with a csv file?
G Gord Dibben Nov 2, 2009 #8 No That particular error indicates a type in the line of code. As I said before.......probably a missing parens. Gord Dibben MS Excel MVP
No That particular error indicates a type in the line of code. As I said before.......probably a missing parens. Gord Dibben MS Excel MVP