Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
save automatically | Excel Discussion (Misc queries) | |||
How do I automatically save a backup copy of Excel 2007 spreadshee | Excel Discussion (Misc queries) | |||
Automatically Save | Excel Programming | |||
How to save a file without overwrite or save a copy? | Setting up and Configuration of Excel | |||
Automatically save a copy of worksheet from C: to Network Drive | Excel Discussion (Misc queries) |