ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to save file (https://www.excelbanter.com/excel-programming/435690-macro-save-file.html)

Jodie

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

Dave Peterson

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

Mike H

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


Jodie

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


Gord Dibben

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



Merlynsdad

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


Jodie

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


Gord Dibben

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



Jodie

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
.



All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com