Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

help required with using cells to generate a filename

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jeffhughes@ntlworld.com - 20 Mar 2006 20:08 GMT
is there a way of clicking on a button that asks you where you want
the file saving, but enters in a filename derived from the contents
of two cells and todays date?

for example if cell A1 contained 'hello' and cell B12 contained
'world' the prompted filename would be 'hello - world - 200306.xls'.

Any help would be appreciated.

TIA
jennifer1970@hotmail.com - 20 Mar 2006 20:21 GMT
Try something like this.

Dim sCell1 As String
Dim sCell2 As String
Dim DateStamp As String

sCell1 = Sheet1.Cells(1, 1).Value
sCell2 = Sheet2.Cells(1, 2).Value
DateStamp = Format(Date, "YYYYMMDD")

Application.GetSaveAsFilename sCell1 & " - " & _
             sCell2 & " - " & _
             DateStamp & ".XLS"
Tom Ogilvy - 20 Mar 2006 20:45 GMT
look at the getsaveasfilename

it has an InitialFilename argument

With Activeworkbook.worksheets(1)
fname = Application.GetSaveAsFilename InitialFilename:= _
 "C:\My Folder\" & .Range("A1").Text &  _
 " - " & .Range("B12").text & " - " & _
 format(Date,"yyyymm") & ".xls"
End with
Activeworkbook.SaveAs fname
But the user could always change it.  If you just want to save the file with
the given name
with worksheets(1)
Activeworkbook.Saveas  "C:\My Folder\" & .Range("A1").Text &  _
 " - " & .Range("B12").text & " - " & _
 format(Date,"yyyymm") & ".xls"
End with

Signature

Regards,
Tom Ogilvy

"Bungle" wrote:

> is there a way of clicking on a button that asks you where you want
> the file saving, but enters in a filename derived from the contents
[quoted text clipped - 6 lines]
>
> TIA
Jay - 20 Mar 2006 21:50 GMT
You could also try this, Bungle, which is a variation of the previous two
suggestions.  Copy it into your VBA editor work area; it's ready to run.
--Jay

Sub fileNameFromCellContentsAndDate()
With ActiveWorkbook.ActiveSheet
   'First part of filename...
    a = Range("A1").Value & " - " & Range("B1").Value & " - "

    'Date part of filename
    b = Format(Date, "ddmmyy")
   
   'Filename extension...
    c = ".xls"
   
   'Use a variable name that is different from 'filename' because filename
is a VBA keyword
    s_filename = a + b + c
   
    fname = Application.GetSaveAsFilename(InitialFileName:=s_filename)
    ActiveWorkbook.SaveAs Filename:=fname
   End With
End Sub

"Bungle" wrote:

> is there a way of clicking on a button that asks you where you want
> the file saving, but enters in a filename derived from the contents
[quoted text clipped - 6 lines]
>
> TIA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.