A
Auric__
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?
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?