-
1
- #1
cklong
Automotive
- Dec 9, 2007
- 10
Adding a counter to a macro is a easy way to find out how useful
your macro is to others. You can even put in hidden comments like
owing you a coffee after so many uses.
I also like to be able to find out what users use it.
Can you tell me how to get the users id name.
'****************************************************************************
Dim path As String
Dim filename As String
Dim scrpt As String
Dim objFSO, objReadFile, contents
Dim ccontents As String
On Error Resume Next
path = "c:\temp\" 'location of file
filename = "test.txt" 'add text name
scrpt = "test" 'name of macro
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile(path & filename, 1, False)
ccontents = objReadFile.ReadAll
If ccontents = "" Then
ccontents = 0
End If
ccontents = ccontents + 1
mut = Round(ccontents / 25)
If ccontents = 100 Then
MsgBox "You have use " & scrpt & " " & ccontents & "times you must really like this program."
ElseIf ccontents = 1 Then
MsgBox "Thank you for trying " & scrpt & " I hope you enjoy this program."
ElseIf ccontents = 25 * mut Then
MsgBox "You have use " & scrpt & " " & ccontents & "times. I think you owe me a coffee"
End If
Set Datos = CATIA.fileSystem.CreateFile(path & filename, True)
Set ostream = Datos.OpenAsTextStream("ForAppending")
ostream.Write ccontents & Chr(10)
ostream.Close
'****************************************************************************
your macro is to others. You can even put in hidden comments like
owing you a coffee after so many uses.
I also like to be able to find out what users use it.
Can you tell me how to get the users id name.
'****************************************************************************
Dim path As String
Dim filename As String
Dim scrpt As String
Dim objFSO, objReadFile, contents
Dim ccontents As String
On Error Resume Next
path = "c:\temp\" 'location of file
filename = "test.txt" 'add text name
scrpt = "test" 'name of macro
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile(path & filename, 1, False)
ccontents = objReadFile.ReadAll
If ccontents = "" Then
ccontents = 0
End If
ccontents = ccontents + 1
mut = Round(ccontents / 25)
If ccontents = 100 Then
MsgBox "You have use " & scrpt & " " & ccontents & "times you must really like this program."
ElseIf ccontents = 1 Then
MsgBox "Thank you for trying " & scrpt & " I hope you enjoy this program."
ElseIf ccontents = 25 * mut Then
MsgBox "You have use " & scrpt & " " & ccontents & "times. I think you owe me a coffee"
End If
Set Datos = CATIA.fileSystem.CreateFile(path & filename, True)
Set ostream = Datos.OpenAsTextStream("ForAppending")
ostream.Write ccontents & Chr(10)
ostream.Close
'****************************************************************************