LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Automatically copy with save?

So, my main biz workbook, I want to automatically copy the saved version
every time I hit save. Here's what I'm using right now:

Private Const MAX_COMPUTERNAME_LENGTH As Long = 31

Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" ( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

Private saveflag As Boolean

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
If saveflag Then
saveflag = False
Else
Dim maxlen As Long, cname As String
Dim to_E As Boolean, to_F As Boolean
maxlen = MAX_COMPUTERNAME_LENGTH + 1
cname = Space$(maxlen)
GetComputerName cname, maxlen
cname = Left(cname, maxlen)
If UCase$(cname) = "LILITH" Then
If Not SaveAsUI Then
saveflag = True
Me.Save
saveflag = False
Cancel = True
Select Case Left$(Me.Path, 1)
Case "E"
to_F = True
Case "F"
to_E = True
Case Else
to_E = True
to_F = True
End Select
If to_E Then CopyFile Me.FullName, _
"E:\Business Records\" & Me.Name, 0
If to_F Then CopyFile Me.FullName, _
"F:\Business Records\" & Me.Name, 0
End If
End If
End If
End Sub

In short:
- if my flag hasn't been set:
- if I'm working from my tablet ("Lilith"):
- set my flag
- do the actual save
- clear my flag
- cancel the pending save that got me here in the first place
- check which drive the book was opened from
- copy as appropriate

I would think that there must be a simpler way to do this, without having
to manually save (so to speak). The problem is, if I just throw a copy in
BeforeSave without going through these gyrations, the current version isn't
what gets copied over, since this runs *before* the save.

Any suggestions?

--
It is more disgraceful to distrust than to be deceived by our friends.
 
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
save automatically Rich[_2_] Excel Discussion (Misc queries) 0 October 18th 07 11:19 AM
How do I automatically save a backup copy of Excel 2007 spreadshee swong74 Excel Discussion (Misc queries) 2 February 13th 07 09:58 PM
Automatically Save Brad Excel Programming 1 January 17th 06 06:38 PM
How to save a file without overwrite or save a copy? SettingChange Setting up and Configuration of Excel 1 November 3rd 05 02:10 AM
Automatically save a copy of worksheet from C: to Network Drive doosbug Excel Discussion (Misc queries) 1 May 3rd 05 06:23 PM


All times are GMT +1. The time now is 04:21 PM.

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"