File name equal cell contents

G

Guest

Is it possible to make an Excel (2003) template (or a macro in the template)
to save a file with a specific cell-contents as file name? For example an
invoice-template where a cell contains the invoice number. I want it to
automatically save the file as "invoice-number".xls in default file location.

Thanks... :)
 
G

Guest

Hi
in a macro
sub save_it()
dim fname
with activeworkbook
fname = .worksheets("sheet1").range("A1").value & ".xls"
..saveas fname
end with
end sub
 
G

Guest

Thanks!!

Just what I was looking for!

Frank Kabel said:
Hi
in a macro
sub save_it()
dim fname
with activeworkbook
fname = .worksheets("sheet1").range("A1").value & ".xls"
.saveas fname
end with
end sub
 
G

Guest

Thanks!

Just what I was looking for!

Frank Kabel said:
Hi
in a macro
sub save_it()
dim fname
with activeworkbook
fname = .worksheets("sheet1").range("A1").value & ".xls"
.saveas fname
end with
end sub
 
D

drvortex

I'm attempting the same thing; however I have a few other options.

1. I want to get the fname from a particular Workbook/Worksheet/Cell.

2. I also want to save the document as a webpage instead of a .xls
file.

3. The worksheet that I'm saving contains charts ONLY. No numbers are
located on this sheet...only charts.

I would greatly appreciate the help. Thanks.

This is what I attempted using the above information. But getting
problems.

Sub save_it()
Dim fname
With ActiveWorkbook
fname =
ActiveWorkbook("2004_Fixes").Worksheets("Sheet2").Range("J5").Value &
".xls"
saveas "C:\Documents and Settings\Drvortex\Desktop\fname.htm"
End With
End Sub
 
G

Guest

One more Q. on the same lines. How do I save it as a PDF - with the filename
being a specific cell ?
Thanks,
Yosef
 
G

Guest

Frank,

I need help... i tried pasteing the code below but nothing happens. can you
help me out. i am trying to set up auto save as at close of workbook. file
name should equal contents of merged cell I10:J10 on sheet2. this save as is
important because it is the customer number which i need for searching as
customer list grows.

also i need to place an auto date that is not volitile in merged cell I1:J1
this is needed to generate the customer number in the first place... right
now i am using Ctrl + ; to place the date in the cell. this is ok if i must
but with expected increase in customers i could save a lot of time if it just
was there...lol

i am running xp with excel (office pro) '03.
 
G

Guest

Is there a way to have two cells in the range, so the the two cells make up
the file name?
 
D

Dave Peterson

fname = .worksheets("sheet1").range("A1").value & _
.worksheets("sheet2").range("z99").value & _
".xls"

You could use the same sheet and adjacent cells, too.
 
G

Guest

Thanks for the information. What would be the full code for this so I can
copy and paste or how could I fix the following code that works with a ctrl-s.

Sub Macro1()
ActiveWorkbook.SaveAs Filename:="C:\" & Range("I5").Value & ".xls", _
FileFormat:=xlNormal, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
End Sub
 
D

Dave Peterson

ActiveWorkbook.SaveAs Filename:="C:\" & Range("I5").Value _
& range("J5").value & ".xls", _

Change the cell to what you want.
 
G

Guest

Thank you very much. This worked, it's great!

Dave Peterson said:
ActiveWorkbook.SaveAs Filename:="C:\" & Range("I5").Value _
& range("J5").value & ".xls", _

Change the cell to what you want.
 
G

Guest

This was a really useful place to start for me, but I have a slightly
different variation!

I have a linked spreadsheet (data on the backend and a really complicated
spreadsheet filled with afore mentioned data on the front end). I need to be
able to save as pdf (or print to PDF) the front page directly to a file.
Hopefully being able to use the handy information here about pulling the
client information from a cell.

Can anyone help with a macro that would allow me to extract just the first
page and save to file; generating a file name from a cell. Saving in PDF if
at all possible....but I would live with .xls
 
D

Dave Peterson

Maybe.....

Dim myFileName as string
with activeworkbook
worksheets(1).copy 'to a new workbook
with activesheet
with .usedrange
.copy
.pastespecial paste:=xlpastevalues 'remove formulas???
end with
'pick up the name from some cells???
myfilename = .range("a1").value & .range("B1").value & ".xls"
myfilename = "C:\my folder\" & myfilename '????
.parent.saveas filename:=myfilename, fileformat:=xlworkbooknormal
.parent.close savechanges:=false
end with
end with

I don't speak the .pdf stuff.
This was a really useful place to start for me, but I have a slightly
different variation!

I have a linked spreadsheet (data on the backend and a really complicated
spreadsheet filled with afore mentioned data on the front end). I need to be
able to save as pdf (or print to PDF) the front page directly to a file.
Hopefully being able to use the handy information here about pulling the
client information from a cell.

Can anyone help with a macro that would allow me to extract just the first
page and save to file; generating a file name from a cell. Saving in PDF if
at all possible....but I would live with .xls
 
N

NeedToKnow

Hi,
I'm getting back to this old question, some problems doesn't go away.

I have this macro and it works fine until invoice has already been saved.
First ofcourse excel wants to know if I want replace earlier file -> no ->
next popup is
"Runtime error 1004
Method 'SaveAs' of object '_Workbook' failed.

How can I get excel to say for ex "file couldn't be saved, check nr or
receiver OR replace older file" This problem doesn't come up if I want
replace old file.

Sub Macro1()

ActiveWorkbook.SaveAs Filename:="D:\SentInvoices\" & Range("C3").Value _
& Range("A8").Value & ".xls", _
FileFormat:=xlNormal, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False

End Sub
 

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