ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   File name equal cell contents (https://www.excelbanter.com/excel-discussion-misc-queries/78899-re-file-name-equal-cell-contents.html)

Petester

File name equal cell contents
 
Is there a way to have two cells in the range, so the the two cells make up
the file name?

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)


Dave Peterson

File name equal cell contents
 
fname = .worksheets("sheet1").range("A1").value & _
.worksheets("sheet2").range("z99").value & _
".xls"

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

Petester wrote:

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

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)


--

Dave Peterson

Petester

File name equal cell contents
 
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

"Dave Peterson" wrote:

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

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

Petester wrote:

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

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)


--

Dave Peterson


Dave Peterson

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

Change the cell to what you want.

Petester wrote:

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

"Dave Peterson" wrote:

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

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

Petester wrote:

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

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)


--

Dave Peterson


--

Dave Peterson

Petester

File name equal cell contents
 
Thank you very much. This worked, it's great!

"Dave Peterson" wrote:

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

Change the cell to what you want.

Petester wrote:

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

"Dave Peterson" wrote:

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

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

Petester wrote:

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

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)

--

Dave Peterson


--

Dave Peterson


southofI10chaos

File name equal cell contents
 
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

"Dave Peterson" wrote:

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

Change the cell to what you want.

Petester wrote:

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

"Dave Peterson" wrote:

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

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

Petester wrote:

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

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)

--

Dave Peterson


--

Dave Peterson


Dave Peterson

File name equal cell contents
 
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.

southofI10chaos wrote:

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

"Dave Peterson" wrote:

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

Change the cell to what you want.

Petester wrote:

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

"Dave Peterson" wrote:

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

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

Petester wrote:

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

"Frank Kabel" wrote:

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


"-tinka" wrote:

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... :-)

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

NeedToKnow

File name equal cell contents
 
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


All times are GMT +1. The time now is 09:29 PM.

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