Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
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? -- Thank you, Jodie |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
With activeworkbook
.saveas filename:="C:\somepath\" _ & left(.worksheets("Somesheetname").range("a1").valu e, 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 Jodie wrote: 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? -- Thank you, Jodie -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
Hi,
Try this ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls" Mike "Jodie" wrote: 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? -- Thank you, Jodie |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
Hi Mike, I am getting an "expected end of statement" error at "sheet1".
-- Thank you, Jodie "Mike H" wrote: Hi, Try this ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls" Mike "Jodie" wrote: 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? -- Thank you, Jodie |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
Did you type the code into your module?
Maybe you missed a parens? Copy the line and it works. Gord Dibben MS Excel MVP On Mon, 2 Nov 2009 11:55:01 -0800, Jodie wrote: Hi Mike, I am getting an "expected end of statement" error at "sheet1". -- Thank you, Jodie "Mike H" wrote: Hi, Try this ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls" Mike "Jodie" wrote: 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? -- Thank you, Jodie |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
Check for typos; it just worked for me. I put 123456 in A1 and now have
123.xls. "Jodie" wrote: Hi Mike, I am getting an "expected end of statement" error at "sheet1". -- Thank you, Jodie "Mike H" wrote: Hi, Try this ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls" Mike "Jodie" wrote: 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? -- Thank you, Jodie |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
Would it have something to do with the fact that I am starting with a csv
file? -- Thank you, Jodie "Merlynsdad" wrote: Check for typos; it just worked for me. I put 123456 in A1 and now have 123.xls. "Jodie" wrote: Hi Mike, I am getting an "expected end of statement" error at "sheet1". -- Thank you, Jodie "Mike H" wrote: Hi, Try this ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls" Mike "Jodie" wrote: 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? -- Thank you, Jodie |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
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 On Mon, 2 Nov 2009 13:49:02 -0800, Jodie wrote: Would it have something to do with the fact that I am starting with a csv file? -- Thank you, Jodie |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to save file
Thank you everyone. I got it to work. :)
-- Thank you, Jodie "Dave Peterson" wrote: With activeworkbook .saveas filename:="C:\somepath\" _ & left(.worksheets("Somesheetname").range("a1").valu e, 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 Jodie wrote: 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? -- Thank you, Jodie -- Dave Peterson . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
2007 Macro to Open File, Delete Contents, Save New File | Excel Discussion (Misc queries) | |||
Macro to save Excel file with date and time in the file name? | Excel Programming | |||
Macro Save File (Unique file name) | Excel Worksheet Functions | |||
Macro to insert values from a file and save another sheet as a .txt file | Excel Programming | |||
Automate open file, update links, run macro, close and save file | Excel Programming |