Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.excel.programming > #110018

Re: list 2 cell values in saveas filename

From GS <gs@v.invalid>
Newsgroups microsoft.public.excel.programming
Subject Re: list 2 cell values in saveas filename
Date 2017-04-21 03:29 -0400
Organization A noiseless patient Spider
Message-ID <odcc73$au1$1@dont-email.me> (permalink)
References <1de0ead1-078b-408a-bff2-4362c9b22f1e@googlegroups.com>

Show all headers | View raw


> 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

Back to microsoft.public.excel.programming | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

list 2 cell values in saveas filename Sabosis <scott.sabo@henryschein.com> - 2017-04-20 19:24 -0700
  Re: list 2 cell values in saveas filename GS <gs@v.invalid> - 2017-04-21 03:29 -0400

csiph-web