PDA

View Full Version : Alter The Name When Saving



Nicola
06-19-2006, 08:31 PM
Ciao,

Code saves ?name?joining of cells A4 + A5 of Sheet ?Shevo? and date:

To produce: Parita64A09 06-06-19

a) Is clearer to read: Parita 64A09 (06-06-19)

b) Clearer: Parita 64A09 (06-06-19 / hh.mm.ss) ?and time?



Sub FareIl()

Dim NewFileName As String
Dim StartWkBk As Workbook
Dim strDate As String

Set StartWkBk = ActiveWorkbook

NewFileName = Sheets("Milano").Range("A4").Text & Sheets("Milano").Range("A5").Text

'Date File
strDate = Format(Now, " yy-mm-dd ")

With StartWkBk
.Sheets(Array("Milano", "Bologna", "Firenze", "Bari")).Copy
ActiveSheet.Select
ActiveWorkbook.SaveAs Filename:=Fld & NewFileName & strDate & ".xls"
End With
ActiveWorkbook.Close SaveChanges:=False
End Sub


Any help to achieve, if possible?? a) or b) ?? : pray2:

Grazie,

Nicola

macleanb
06-20-2006, 12:06 AM
Ciao,

Code saves ?name?joining of cells A4 + A5 of Sheet ?Shevo? and date:

To produce: Parita64A09 06-06-19

a) Is clearer to read: Parita 64A09 (06-06-19)

b) Clearer: Parita 64A09 (06-06-19 / hh.mm.ss) ?and time?



Sub FareIl()

Dim NewFileName As String

NewFileName = Sheets("Milano").Range("A4").Text & " " & Sheets("Milano").Range("A5").Text & "(" & Format(Now, " yy-mm-dd HH:MM ") & ")"
ActiveWorkbook.SaveAs Filename:=Fld & NewFileName & strDate & ".xls"
ActiveWorkbook.Close SaveChanges:=False
End Sub


Any help to achieve, if possible?? a) or b) ?? : pray2:

Grazie,

Nicola

mdmackillop
06-20-2006, 05:49 AM
Hi Nicola,
Welcome to VBAX.
If you want all sheets in a copy of the workbook, you can use SaveCopyAs. Readability is a personal thing, so your choice really, but you cannot use the "/" character in a file name.

Here's some code for a SaveCopyAs method

Sub FareIl()

Dim NewFileName As String
Dim strDate As String
Dim Fld As String

Set StartWkBk = ActiveWorkbook
Fld = ActiveWorkbook.Path & "\"

With Sheets("Milano")
NewFileName = .[A4] & .[A5]
End With

strDate = Format(Now, " yy-mm-dd ")

ActiveWorkbook.SaveCopyAs Filename:=Fld & NewFileName & strDate & ".xls"
End Sub