Macro to save file

J

Jodie

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

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

Hi,

Try this

ActiveWorkbook.SaveAs Filename:=Left(Sheets("Sheet1").Range("A1"), 3) & ".xls"

Mike
 
G

Gord Dibben

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

Check for typos; it just worked for me. I put 123456 in A1 and now have
123.xls.
 
G

Gord Dibben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top