J
Janine_ribbonspace
Hi,
Anyone have any ideas how I can alter this code when template resides in
STARTUP to stamp registry with number of times accessed? It assumes AUTONEW
as a template would run but in STARTUP it is accessed not File New.
Can I change AutoNew to be AutoOpen? I don't have VBA help access available
on this machine as it is Technical Preview.
Crude but effective until it resides in STARTUP and is not used as an
autonew template.
Many thanks.
Option Explicit
Public Sub TrialTest()
'Pop up a message and close the document if it has
'been used more than x times or for more than x days:
On Error GoTo Err_AutoNew
Const iMaxRuns As Integer = 1
Const lMaxDays As Long = 1
Dim iTimesRun As Integer
Dim dtFirstRun As Date
Dim bOKToRun As Boolean
Dim sTimesRun As String
Dim sFirstRun As String
Dim sErrorMessage As String
sTimesRun = GetSetting("Word", "MyKeySection", "TimesRun")
sFirstRun = GetSetting("Word", "MyKeySection", "FirstRun")
If IsNumeric(sTimesRun) Then
iTimesRun = CInt(sTimesRun)
Else
iTimesRun = 0
End If
iTimesRun = iTimesRun + 1
If IsDate(sFirstRun) Then
dtFirstRun = CDate(sFirstRun)
Else
dtFirstRun = Now
Call SaveSetting("Word", "MyKeySection", "FirstRun",
CStr(dtFirstRun))
End If
bOKToRun = True
If iTimesRun > iMaxRuns Then
bOKToRun = False
sErrorMessage = "You have used this template " _
& iTimesRun & " times. The maximum limit is " _
& iMaxRuns & " uses. Visit www.com to " _
& "xxxxxxxx latest version."
End If
If DateDiff("d", dtFirstRun, Now) > lMaxDays Then
bOKToRun = False
sErrorMessage = "You have used this template since " _
& dtFirstRun & ". It can only be used for " _
& lMaxDays & " days. Visit www.com to " _
& "xxxxxxxx latest version."
End If
If bOKToRun Then
Call SaveSetting("Word", "MyKeySection", "TimesRun",
CStr(iTimesRun))
Else
MsgBox sErrorMessage
ActiveDocument.Close (wdDoNotSaveChanges)
End If
Exit_AutoNew:
Exit Sub
Err_AutoNew:
MsgBox Err.Description
Resume Exit_AutoNew
End Sub
Anyone have any ideas how I can alter this code when template resides in
STARTUP to stamp registry with number of times accessed? It assumes AUTONEW
as a template would run but in STARTUP it is accessed not File New.
Can I change AutoNew to be AutoOpen? I don't have VBA help access available
on this machine as it is Technical Preview.
Crude but effective until it resides in STARTUP and is not used as an
autonew template.
Many thanks.
Option Explicit
Public Sub TrialTest()
'Pop up a message and close the document if it has
'been used more than x times or for more than x days:
On Error GoTo Err_AutoNew
Const iMaxRuns As Integer = 1
Const lMaxDays As Long = 1
Dim iTimesRun As Integer
Dim dtFirstRun As Date
Dim bOKToRun As Boolean
Dim sTimesRun As String
Dim sFirstRun As String
Dim sErrorMessage As String
sTimesRun = GetSetting("Word", "MyKeySection", "TimesRun")
sFirstRun = GetSetting("Word", "MyKeySection", "FirstRun")
If IsNumeric(sTimesRun) Then
iTimesRun = CInt(sTimesRun)
Else
iTimesRun = 0
End If
iTimesRun = iTimesRun + 1
If IsDate(sFirstRun) Then
dtFirstRun = CDate(sFirstRun)
Else
dtFirstRun = Now
Call SaveSetting("Word", "MyKeySection", "FirstRun",
CStr(dtFirstRun))
End If
bOKToRun = True
If iTimesRun > iMaxRuns Then
bOKToRun = False
sErrorMessage = "You have used this template " _
& iTimesRun & " times. The maximum limit is " _
& iMaxRuns & " uses. Visit www.com to " _
& "xxxxxxxx latest version."
End If
If DateDiff("d", dtFirstRun, Now) > lMaxDays Then
bOKToRun = False
sErrorMessage = "You have used this template since " _
& dtFirstRun & ". It can only be used for " _
& lMaxDays & " days. Visit www.com to " _
& "xxxxxxxx latest version."
End If
If bOKToRun Then
Call SaveSetting("Word", "MyKeySection", "TimesRun",
CStr(iTimesRun))
Else
MsgBox sErrorMessage
ActiveDocument.Close (wdDoNotSaveChanges)
End If
Exit_AutoNew:
Exit Sub
Err_AutoNew:
MsgBox Err.Description
Resume Exit_AutoNew
End Sub