B
Bob
I am using the VB code the expires and deletes a workbook after a certain
number of days. I also have VB that prevent the user to save the file if not
the administrator, and code that stops the "save as" dialog box.
I want to email the file to another, and on the first open, the workbook is
saved to a specific file path and folder. It will overwrite the existing
file and this save is not prevented by the save only by user "" vb code. Is
this possible.
Below is my current workbook code:
Private Sub Workbook_Open()
Dim StartTime#, CurrentTime#
Const TrialPeriod# = 10
Const ObscurePath$ = "C:\"
Const ObscureFile$ = "testlog3.Log"
'*****************************************
If Dir(ObscurePath & ObscureFile) = Empty Then
MsgBox vbLf & "update installed"
StartTime = Format(Now, "#0.#########0")
Open ObscurePath & ObscureFile For Output As #1
Print #1, StartTime
Else
Open ObscurePath & ObscureFile For Input As #1
Input #1, StartTime
CurrentTime = Format(Now, "#0.#########0")
If CurrentTime < StartTime + TrialPeriod Then
Close #1
Exit Sub
Else
If [A1] <> "Expired" Then
MsgBox vbLf & "expired"
With ThisWorkbook
.Saved = True
.ChangeFileAccess Mode:=xlReadOnly
Kill .FullName
.Close False
End With
Close #1
Application.Quit
ElseIf [A1] = "Expired" Then
Close #1
Application.Quit
End If
End If
End If
Close #1
End Sub
----
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.UserName <> "Administrator" Then
MsgBox (" NOT AUTHORIZED"), vbOKCancel, "SAVING
ERROR"
Cancel = True
End If
End Sub
number of days. I also have VB that prevent the user to save the file if not
the administrator, and code that stops the "save as" dialog box.
I want to email the file to another, and on the first open, the workbook is
saved to a specific file path and folder. It will overwrite the existing
file and this save is not prevented by the save only by user "" vb code. Is
this possible.
Below is my current workbook code:
Private Sub Workbook_Open()
Dim StartTime#, CurrentTime#
Const TrialPeriod# = 10
Const ObscurePath$ = "C:\"
Const ObscureFile$ = "testlog3.Log"
'*****************************************
If Dir(ObscurePath & ObscureFile) = Empty Then
MsgBox vbLf & "update installed"
StartTime = Format(Now, "#0.#########0")
Open ObscurePath & ObscureFile For Output As #1
Print #1, StartTime
Else
Open ObscurePath & ObscureFile For Input As #1
Input #1, StartTime
CurrentTime = Format(Now, "#0.#########0")
If CurrentTime < StartTime + TrialPeriod Then
Close #1
Exit Sub
Else
If [A1] <> "Expired" Then
MsgBox vbLf & "expired"
With ThisWorkbook
.Saved = True
.ChangeFileAccess Mode:=xlReadOnly
Kill .FullName
.Close False
End With
Close #1
Application.Quit
ElseIf [A1] = "Expired" Then
Close #1
Application.Quit
End If
End If
End If
Close #1
End Sub
----
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.UserName <> "Administrator" Then
MsgBox (" NOT AUTHORIZED"), vbOKCancel, "SAVING
ERROR"
Cancel = True
End If
End Sub