Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Auto save at specific times with changing saveas name

I have an Excel file that I need to save-as automatically to a static
location of my choosing at 12Noon, 5:00pm & 11:59pm every day the file is
used, which is every day. When save-as occurs at these times, I need the file
to save with a name like "MyFile_todaysdate_1200.xls" or
"MyFile_todaysdate_1700.xls" or "MyFile_todaysdate_2359.xls". I know a file
can not use "/" in the filename so the date can look like 061808.
I just have not been able to peice this together with what little I know
along with posts I've read. I really appreciate any assistance with this.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Auto save at specific times with changing saveas name

hello,
Type this in a notepad, edit the path for the .xls document in the
code and save it as a .VBS file. Setup Windows scheduler to run
this .VBS file at 12pm, 5pm, and 11:59pm and it'll do what your
looking for.

Dim xlApp
set xlApp = CreateObject("Excel.Application")
xlapp.workbooks.open "C:\Documents and Settings\G\Desktop\Z\test.xls"
xlApp.Visible = True
set xlwb = xlapp.activeworkbook
Dim idate
Dim itime

idate = Month(Now) & Day(Now) & Year(Now) 'Format(Date, "mmddyy")
itime = FormatDateTime(Round(Time * 24, 0.1) / 24,vbshorttime)
'Round(Time * 24, 0.1) / 24, "hmm")

Select Case itime
Case "12:00","13:00"
itime = 1200
Case "17:00","18:00"
itime = 1700
Case "22:00","23:00","24:00"
itime = 2359
End Select

xlWB.saveas "C:\Documents and Settings\G\Desktop\Z\" & "MyFile_" &
idate & "_" & itime & ".xls"
xlWB.close
xlapp.quit
set xlwb = nothing
set xlapp = nothing
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Auto save at specific times with changing saveas name

Will this work with the file being open all day, not being closed until after
midnight, and constantly updated thru out the day by multiple users at the
same time in a ShareWorkbook status? I will try it and let you know the
result(s). Thank you very much!

"GTVT06" wrote:

hello,
Type this in a notepad, edit the path for the .xls document in the
code and save it as a .VBS file. Setup Windows scheduler to run
this .VBS file at 12pm, 5pm, and 11:59pm and it'll do what your
looking for.

Dim xlApp
set xlApp = CreateObject("Excel.Application")
xlapp.workbooks.open "C:\Documents and Settings\G\Desktop\Z\test.xls"
xlApp.Visible = True
set xlwb = xlapp.activeworkbook
Dim idate
Dim itime

idate = Month(Now) & Day(Now) & Year(Now) 'Format(Date, "mmddyy")
itime = FormatDateTime(Round(Time * 24, 0.1) / 24,vbshorttime)
'Round(Time * 24, 0.1) / 24, "hmm")

Select Case itime
Case "12:00","13:00"
itime = 1200
Case "17:00","18:00"
itime = 1700
Case "22:00","23:00","24:00"
itime = 2359
End Select

xlWB.saveas "C:\Documents and Settings\G\Desktop\Z\" & "MyFile_" &
idate & "_" & itime & ".xls"
xlWB.close
xlapp.quit
set xlwb = nothing
set xlapp = nothing

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Auto save at specific times with changing saveas name

Here you go:
In this code it assumes that if an open instance of Excel exists then
that means that "Test.xls" is already open. If an instance of Excel
don't exist then it will open excel, open the file, save it, and close
excel.
It'll save the file as "MyFile_" & irdate & "_" & irtime & ".xls" and
then save it back to "Test.xls" so that way the next time the script
run's it'll easily itentify the file.

Dim objXL
On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
If Not TypeName(objXL) = "Empty" Then
objXL.Workbooks("Test.xls").Activate
set xlswb = objXL.activeworkbook
Dim irdate
Dim irtime


irdate = Month(Now) & Day(Now) & Year(Now) 'Format(Date,
"mmddyy")
irtime = FormatDateTime(Round(Time * 24, 0.1) / 24,vbshorttime)



Select Case irtime
Case "12:00","13:00"
irtime = 1200
Case "17:00","18:00"
irtime = 1700
Case "22:00","23:00","24:00"
irtime = 2359
End Select


xlswb.saveas "C:\Documents and Settings\DT42921\Desktop\TEST VBS\" &
"MyFile_" & irdate & "_" & irtime & ".xls"
xlswb.saveas "C:\Documents and Settings\DT42921\Desktop\TEST VBS
\Test.xls.xls"

set xlswb = nothing
set objXL = nothing

Else

Dim xlApp
set xlApp = CreateObject("Excel.Application")
xlapp.workbooks.open "C:\Documents and Settings\DT42921\Desktop\TEST
VBS\test.xls"
xlApp.Visible = True
set xlwb = xlapp.activeworkbook
Dim idate
Dim itime


idate = Month(Now) & Day(Now) & Year(Now) 'Format(Date, "mmddyy")
itime = FormatDateTime(Round(Time * 24, 0.1) / 24,vbshorttime)



Select Case itime
Case "12:00","13:00"
itime = 1200
Case "17:00","18:00"
itime = 1700
Case "22:00","23:00","24:00"
itime = 2359
End Select


xlWB.saveas "C:\Documents and Settings\DT42921\Desktop\TEST VBS\" &
"MyFile_" & idate & "_" & itime & ".xls"
xlWB.close
xlapp.quit
set xlwb = nothing
set xlapp = nothing

End If
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Auto save at specific times with changing saveas name

With some tweeking, this will work great. Thank you!

"GTVT06" wrote:

Here you go:
In this code it assumes that if an open instance of Excel exists then
that means that "Test.xls" is already open. If an instance of Excel
don't exist then it will open excel, open the file, save it, and close
excel.
It'll save the file as "MyFile_" & irdate & "_" & irtime & ".xls" and
then save it back to "Test.xls" so that way the next time the script
run's it'll easily itentify the file.

Dim objXL
On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
If Not TypeName(objXL) = "Empty" Then
objXL.Workbooks("Test.xls").Activate
set xlswb = objXL.activeworkbook
Dim irdate
Dim irtime


irdate = Month(Now) & Day(Now) & Year(Now) 'Format(Date,
"mmddyy")
irtime = FormatDateTime(Round(Time * 24, 0.1) / 24,vbshorttime)



Select Case irtime
Case "12:00","13:00"
irtime = 1200
Case "17:00","18:00"
irtime = 1700
Case "22:00","23:00","24:00"
irtime = 2359
End Select


xlswb.saveas "C:\Documents and Settings\DT42921\Desktop\TEST VBS\" &
"MyFile_" & irdate & "_" & irtime & ".xls"
xlswb.saveas "C:\Documents and Settings\DT42921\Desktop\TEST VBS
\Test.xls.xls"

set xlswb = nothing
set objXL = nothing

Else

Dim xlApp
set xlApp = CreateObject("Excel.Application")
xlapp.workbooks.open "C:\Documents and Settings\DT42921\Desktop\TEST
VBS\test.xls"
xlApp.Visible = True
set xlwb = xlapp.activeworkbook
Dim idate
Dim itime


idate = Month(Now) & Day(Now) & Year(Now) 'Format(Date, "mmddyy")
itime = FormatDateTime(Round(Time * 24, 0.1) / 24,vbshorttime)



Select Case itime
Case "12:00","13:00"
itime = 1200
Case "17:00","18:00"
itime = 1700
Case "22:00","23:00","24:00"
itime = 2359
End Select


xlWB.saveas "C:\Documents and Settings\DT42921\Desktop\TEST VBS\" &
"MyFile_" & idate & "_" & itime & ".xls"
xlWB.close
xlapp.quit
set xlwb = nothing
set xlapp = nothing

End If



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Auto save at specific times with changing saveas name

Your welcome.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto save Spread sheet as htm to a specific location Saving is tough Excel Discussion (Misc queries) 0 October 29th 08 03:46 PM
disable save and saveas from menubar and save via command button Steve E Excel Programming 5 September 13th 06 11:51 PM
save / saveas specific filename.....with a difference! michael.beckinsale Excel Programming 7 September 11th 06 10:02 AM
2 Part question involving SaveAs and Auto Save when quit. ryanmhess Excel Programming 0 September 1st 05 09:47 PM
Disabling Saveas and saving file with a specific name only Hari[_3_] Excel Programming 3 June 14th 04 08:34 PM


All times are GMT +1. The time now is 11:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"