PC Review


Reply
Thread Tools Rate Thread

Adding date to file name when saving and over writing a existing f

 
 
Nils Titley
Guest
Posts: n/a
 
      21st Mar 2008
I want to add a date at end of the file name. How do I do that?

Also I want to over write a file if it exist at this location but I don't
want a box to pop up.

Dim WBNew As Workbook

WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"

Look like this: Lift Logger Process 031908.xls

Thanks

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      21st Mar 2008
Sub writebook()
Dim WBNew As Workbook
Application.EnableEvents = False
String_Date = Format(Date, "mmddyy")
WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process" & _
String_Date & ".xls"
Application.EnableEvents = True

End Sub

"Nils Titley" wrote:

> I want to add a date at end of the file name. How do I do that?
>
> Also I want to over write a file if it exist at this location but I don't
> want a box to pop up.
>
> Dim WBNew As Workbook
>
> WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
>
> Look like this: Lift Logger Process 031908.xls
>
> Thanks
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      21st Mar 2008
Dim NewName as string
NewName = "C:\temp\lift logger\lift logger process " _
& format(date, "mmddyy") & ".xls"

application.displayalerts = false
wbnew.saveas filename:=newname, fileformat:=newname
application.displayalerts = true

========
If you didn't know the name of the workbook, you could strip the .xls (and
mmddyy if you had it), too.

Nils Titley wrote:
>
> I want to add a date at end of the file name. How do I do that?
>
> Also I want to over write a file if it exist at this location but I don't
> want a box to pop up.
>
> Dim WBNew As Workbook
>
> WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
>
> Look like this: Lift Logger Process 031908.xls
>
> Thanks


--

Dave Peterson
 
Reply With Quote
 
Nils Titley
Guest
Posts: n/a
 
      21st Mar 2008
Dave,

wbnew.saveas filename:=newname, fileformat:=newname

It worked if I removed the " ,fileformat:=newname". What is that doing and
why won't it work with it?

Thanks

"Dave Peterson" wrote:

> Dim NewName as string
> NewName = "C:\temp\lift logger\lift logger process " _
> & format(date, "mmddyy") & ".xls"
>
> application.displayalerts = false
> wbnew.saveas filename:=newname, fileformat:=newname
> application.displayalerts = true
>
> ========
> If you didn't know the name of the workbook, you could strip the .xls (and
> mmddyy if you had it), too.
>
> Nils Titley wrote:
> >
> > I want to add a date at end of the file name. How do I do that?
> >
> > Also I want to over write a file if it exist at this location but I don't
> > want a box to pop up.
> >
> > Dim WBNew As Workbook
> >
> > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
> >
> > Look like this: Lift Logger Process 031908.xls
> >
> > Thanks

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      21st Mar 2008
The "fileformat" parameter tells Excel in what format to save the file, such
as in Text, Comma Separated Values, Excel95 and so on. Most of the time you
can omit this and save the file as a normal Excel xls file.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



"Nils Titley" <(E-Mail Removed)> wrote in message
news:36037B10-CE45-416C-94D6-(E-Mail Removed)...
> Dave,
>
> wbnew.saveas filename:=newname, fileformat:=newname
>
> It worked if I removed the " ,fileformat:=newname". What is that doing
> and
> why won't it work with it?
>
> Thanks
>
> "Dave Peterson" wrote:
>
>> Dim NewName as string
>> NewName = "C:\temp\lift logger\lift logger process " _
>> & format(date, "mmddyy") & ".xls"
>>
>> application.displayalerts = false
>> wbnew.saveas filename:=newname, fileformat:=newname
>> application.displayalerts = true
>>
>> ========
>> If you didn't know the name of the workbook, you could strip the .xls
>> (and
>> mmddyy if you had it), too.
>>
>> Nils Titley wrote:
>> >
>> > I want to add a date at end of the file name. How do I do that?
>> >
>> > Also I want to over write a file if it exist at this location but I
>> > don't
>> > want a box to pop up.
>> >
>> > Dim WBNew As Workbook
>> >
>> > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
>> >
>> > Look like this: Lift Logger Process 031908.xls
>> >
>> > Thanks

>>
>> --
>>
>> Dave Peterson
>>


 
Reply With Quote
 
Nils Titley
Guest
Posts: n/a
 
      21st Mar 2008
Thanks Joel, Dave and Chip for your help.



"Chip Pearson" wrote:

> The "fileformat" parameter tells Excel in what format to save the file, such
> as in Text, Comma Separated Values, Excel95 and so on. Most of the time you
> can omit this and save the file as a normal Excel xls file.
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional
> Excel Product Group
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
>
> "Nils Titley" <(E-Mail Removed)> wrote in message
> news:36037B10-CE45-416C-94D6-(E-Mail Removed)...
> > Dave,
> >
> > wbnew.saveas filename:=newname, fileformat:=newname
> >
> > It worked if I removed the " ,fileformat:=newname". What is that doing
> > and
> > why won't it work with it?
> >
> > Thanks
> >
> > "Dave Peterson" wrote:
> >
> >> Dim NewName as string
> >> NewName = "C:\temp\lift logger\lift logger process " _
> >> & format(date, "mmddyy") & ".xls"
> >>
> >> application.displayalerts = false
> >> wbnew.saveas filename:=newname, fileformat:=newname
> >> application.displayalerts = true
> >>
> >> ========
> >> If you didn't know the name of the workbook, you could strip the .xls
> >> (and
> >> mmddyy if you had it), too.
> >>
> >> Nils Titley wrote:
> >> >
> >> > I want to add a date at end of the file name. How do I do that?
> >> >
> >> > Also I want to over write a file if it exist at this location but I
> >> > don't
> >> > want a box to pop up.
> >> >
> >> > Dim WBNew As Workbook
> >> >
> >> > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
> >> >
> >> > Look like this: Lift Logger Process 031908.xls
> >> >
> >> > Thanks
> >>
> >> --
> >>
> >> Dave Peterson
> >>

>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      21st Mar 2008
It was a stupid typo.

I meant this:

wbnew.saveas filename:=newname, fileformat:=xlworkbooknormal

(I like being specific.)



Nils Titley wrote:
>
> Dave,
>
> wbnew.saveas filename:=newname, fileformat:=newname
>
> It worked if I removed the " ,fileformat:=newname". What is that doing and
> why won't it work with it?
>
> Thanks
>
> "Dave Peterson" wrote:
>
> > Dim NewName as string
> > NewName = "C:\temp\lift logger\lift logger process " _
> > & format(date, "mmddyy") & ".xls"
> >
> > application.displayalerts = false
> > wbnew.saveas filename:=newname, fileformat:=newname
> > application.displayalerts = true
> >
> > ========
> > If you didn't know the name of the workbook, you could strip the .xls (and
> > mmddyy if you had it), too.
> >
> > Nils Titley wrote:
> > >
> > > I want to add a date at end of the file name. How do I do that?
> > >
> > > Also I want to over write a file if it exist at this location but I don't
> > > want a box to pop up.
> > >
> > > Dim WBNew As Workbook
> > >
> > > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
> > >
> > > Look like this: Lift Logger Process 031908.xls
> > >
> > > Thanks

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Nils Titley
Guest
Posts: n/a
 
      22nd Mar 2008
Dave

The date is working well but now I want to add time to the file. I thought
I could do this but it doesn't like it. What do I have to do, please?

NewName = "C:\temp\lift logger report\Lift Logger Process Report " _
& Format(Date, "ddmmyy") & Time & ".xls"

Thanks

"Dave Peterson" wrote:

> It was a stupid typo.
>
> I meant this:
>
> wbnew.saveas filename:=newname, fileformat:=xlworkbooknormal
>
> (I like being specific.)
>
>
>
> Nils Titley wrote:
> >
> > Dave,
> >
> > wbnew.saveas filename:=newname, fileformat:=newname
> >
> > It worked if I removed the " ,fileformat:=newname". What is that doing and
> > why won't it work with it?
> >
> > Thanks
> >
> > "Dave Peterson" wrote:
> >
> > > Dim NewName as string
> > > NewName = "C:\temp\lift logger\lift logger process " _
> > > & format(date, "mmddyy") & ".xls"
> > >
> > > application.displayalerts = false
> > > wbnew.saveas filename:=newname, fileformat:=newname
> > > application.displayalerts = true
> > >
> > > ========
> > > If you didn't know the name of the workbook, you could strip the .xls (and
> > > mmddyy if you had it), too.
> > >
> > > Nils Titley wrote:
> > > >
> > > > I want to add a date at end of the file name. How do I do that?
> > > >
> > > > Also I want to over write a file if it exist at this location but I don't
> > > > want a box to pop up.
> > > >
> > > > Dim WBNew As Workbook
> > > >
> > > > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
> > > >
> > > > Look like this: Lift Logger Process 031908.xls
> > > >
> > > > Thanks
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Mar 2008
NewName = "C:\temp\lift logger report\Lift Logger Process Report " _
& Format(now, "yyyymmdd_hhmmss") & ".xls"

Notice that the code uses Now instead of Date.

I like the yyyymmdd_hhmmss format (descending order of units of time). But you
could change it to what you like.



Nils Titley wrote:
>
> Dave
>
> The date is working well but now I want to add time to the file. I thought
> I could do this but it doesn't like it. What do I have to do, please?
>
> NewName = "C:\temp\lift logger report\Lift Logger Process Report " _
> & Format(Date, "ddmmyy") & Time & ".xls"
>
> Thanks
>
> "Dave Peterson" wrote:
>
> > It was a stupid typo.
> >
> > I meant this:
> >
> > wbnew.saveas filename:=newname, fileformat:=xlworkbooknormal
> >
> > (I like being specific.)
> >
> >
> >
> > Nils Titley wrote:
> > >
> > > Dave,
> > >
> > > wbnew.saveas filename:=newname, fileformat:=newname
> > >
> > > It worked if I removed the " ,fileformat:=newname". What is that doing and
> > > why won't it work with it?
> > >
> > > Thanks
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > Dim NewName as string
> > > > NewName = "C:\temp\lift logger\lift logger process " _
> > > > & format(date, "mmddyy") & ".xls"
> > > >
> > > > application.displayalerts = false
> > > > wbnew.saveas filename:=newname, fileformat:=newname
> > > > application.displayalerts = true
> > > >
> > > > ========
> > > > If you didn't know the name of the workbook, you could strip the .xls (and
> > > > mmddyy if you had it), too.
> > > >
> > > > Nils Titley wrote:
> > > > >
> > > > > I want to add a date at end of the file name. How do I do that?
> > > > >
> > > > > Also I want to over write a file if it exist at this location but I don't
> > > > > want a box to pop up.
> > > > >
> > > > > Dim WBNew As Workbook
> > > > >
> > > > > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
> > > > >
> > > > > Look like this: Lift Logger Process 031908.xls
> > > > >
> > > > > Thanks
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Nils Titley
Guest
Posts: n/a
 
      22nd Mar 2008
Dave

Thank works but the time looks weired. I had trouble recognizing it. Can't
I make it look more like time? Say 12:11:30 ? There must be a better way?

Thanks for your help.


"Dave Peterson" wrote:

> NewName = "C:\temp\lift logger report\Lift Logger Process Report " _
> & Format(now, "yyyymmdd_hhmmss") & ".xls"
>
> Notice that the code uses Now instead of Date.
>
> I like the yyyymmdd_hhmmss format (descending order of units of time). But you
> could change it to what you like.
>
>
>
> Nils Titley wrote:
> >
> > Dave
> >
> > The date is working well but now I want to add time to the file. I thought
> > I could do this but it doesn't like it. What do I have to do, please?
> >
> > NewName = "C:\temp\lift logger report\Lift Logger Process Report " _
> > & Format(Date, "ddmmyy") & Time & ".xls"
> >
> > Thanks
> >
> > "Dave Peterson" wrote:
> >
> > > It was a stupid typo.
> > >
> > > I meant this:
> > >
> > > wbnew.saveas filename:=newname, fileformat:=xlworkbooknormal
> > >
> > > (I like being specific.)
> > >
> > >
> > >
> > > Nils Titley wrote:
> > > >
> > > > Dave,
> > > >
> > > > wbnew.saveas filename:=newname, fileformat:=newname
> > > >
> > > > It worked if I removed the " ,fileformat:=newname". What is that doing and
> > > > why won't it work with it?
> > > >
> > > > Thanks
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > Dim NewName as string
> > > > > NewName = "C:\temp\lift logger\lift logger process " _
> > > > > & format(date, "mmddyy") & ".xls"
> > > > >
> > > > > application.displayalerts = false
> > > > > wbnew.saveas filename:=newname, fileformat:=newname
> > > > > application.displayalerts = true
> > > > >
> > > > > ========
> > > > > If you didn't know the name of the workbook, you could strip the .xls (and
> > > > > mmddyy if you had it), too.
> > > > >
> > > > > Nils Titley wrote:
> > > > > >
> > > > > > I want to add a date at end of the file name. How do I do that?
> > > > > >
> > > > > > Also I want to over write a file if it exist at this location but I don't
> > > > > > want a box to pop up.
> > > > > >
> > > > > > Dim WBNew As Workbook
> > > > > >
> > > > > > WBNew.SaveAs "C:\Temp\Lift Logger\Lift Logger Process.xls"
> > > > > >
> > > > > > Look like this: Lift Logger Process 031908.xls
> > > > > >
> > > > > > Thanks
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to existing XML file Rookie Microsoft C# .NET 4 10th Mar 2010 09:09 AM
Message about File Already Existing When Saving Charles Allen Microsoft Excel Discussion 1 28th Apr 2009 12:31 PM
Seeing existing file names when saving jkiser Microsoft Excel Misc 1 12th Dec 2008 06:27 PM
Adding 5 yrs to and existing date =?Utf-8?B?bWF6YWxhbQ==?= Microsoft Access 1 25th Sep 2007 04:12 PM
writing to the existing file. nasirmajor@yahoo.com Microsoft ASP .NET 1 17th Jul 2006 11:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:53 AM.