Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Macro to Open File, Delete Contents, Save New File Flintstone[_2_] Excel Discussion (Misc queries) 2 February 1st 10 11:25 PM
Macro to save Excel file with date and time in the file name? sonic_d_hog Excel Programming 2 January 5th 06 05:57 PM
Macro Save File (Unique file name) SJC Excel Worksheet Functions 5 October 27th 05 10:09 PM
Macro to insert values from a file and save another sheet as a .txt file Frank[_16_] Excel Programming 2 August 28th 03 01:07 AM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"