View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default list 2 cell values in saveas filename

Hello

I am trying to use VBA to save a file and want two cell values in the new
filename. One is a text value in cell B2, the other is a date in cell B1. I
have tried this many ways but cannot get it to work. Below is a modified
example that I found on the net:

Sub filesave()
Dim Path As String
Dim Rep As String
Dim RDate As Date
Path = "C:\MyFiles\"
Rep = Range("B2").Value
RDate = Range("B1").Value
ActiveWorkbook.SaveAs filename:=Path & Rep & RDate & ".xls", _
FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
End Sub


Please let me know what is causing this code to error out.

Thanks

Scott


You need to convert the date var to a string so it matches the SaveAs filename
data type! Try this instead...

Const sPath$ = "C:\MyFiles\"
ActiveWorkbook.SaveAs filename:= sPath & Range("B2") & Range("B1") & ".xls"

...as all the other args are default values and so not needed.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion