Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Visual Basic - Tuesday

I have an excel file.
In VB when the file is opened, I want it to identify that it is a Tuesday
and the file must save (only the first time it is opened on a Tuesday) onto
a different location as back up only once on a Tuesday. If the file is
closed on a Tuesday and re-opened on a Tuesday, it must not overwrite the
saved copy.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Visual Basic - Tuesday

Ronel,

Put the following code in the ThisWorkbook code module.

Private Sub Workbook_Open()
Dim SavedDate As Variant
Dim HasSaved As Variant
If Weekday(Now) = vbTuesday Then
With ThisWorkbook
On Error Resume Next
Err.Clear
SavedDate = .Names("SavedDate").RefersTo
If Err.Number < 0 Then
SavedDate = CDate(CLng(Now)) - 1
Else
SavedDate = CDate(Mid(.Names("SavedDate").RefersTo, 2))
End If
Err.Clear
HasSaved = .Names("HasSaved").RefersTo
If Err.Number < 0 Then
HasSaved = False
Else
HasSaved = CBool(Mid(.Names("HasSaved").RefersTo, 2))
End If
If (SavedDate < CLng(Now)) And (HasSaved = False) Then
.SaveCopyAs Filename:=Left(.FullName, Len(.FullName) - 4) & _
"\Backup\" & "_" & Format(Now, "dd_mmm_yyyy") & ".xls"
End If
.Names.Add Name:="SavedDate", RefersTo:=CDate(CLng(Now)),
Visible:=False
.Names.Add Name:="HasSaved", RefersTo:=True, Visible:=False
End With
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"Ronel" wrote in message
...
I have an excel file.
In VB when the file is opened, I want it to identify that it is a Tuesday
and the file must save (only the first time it is opened on a Tuesday)
onto
a different location as back up only once on a Tuesday. If the file is
closed on a Tuesday and re-opened on a Tuesday, it must not overwrite the
saved copy.


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
Is Visual Basic the same as Visual Studio 2008? Mike Stewart Excel Worksheet Functions 5 January 11th 09 04:58 PM
Programmatic access to visual basic project via Visual FoxPro Jim Rech Excel Programming 0 January 11th 07 01:53 PM
Make visual basic truely visual! GraphicalGuy Excel Programming 0 October 20th 06 05:53 PM
Can I run Visual Basic procedure using Excel Visual Basic editor? john.jacobs71[_2_] Excel Programming 3 December 26th 05 02:22 PM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM


All times are GMT +1. The time now is 03:39 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"