hdegraw
09-11-2013, 10:46 AM
I am new to the site and first time user of vba. The code I have below inserts the Windows User Name in one column of a table and the date and time in the next column when a check box is clicked. I would like to add vba programming that would take that name and date of the document when the check box is unclicked. Currently you can unclick the box and it updates the time and that is it. Thank you for your help.
Option Explicit
'api call for obtaining the username
Private Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long)
Public Function WindowsUserName() As String
' ---------------------------------------------
'Function to extract the name:
' ---------------------------------------------
Dim szBuffer As String * 100
Dim lBufferLen As Long
lBufferLen = 100
If CBool(GetUserName(szBuffer, lBufferLen)) Then
WindowsUserName = Left$(szBuffer, lBufferLen - 1)
Else
WindowsUserName = CStr(Empty)
End If
End Function
Private Sub CheckBox1_Click()
Selection.MoveRight Unit:=wdCell Selection.TypeText Text:=WindowsUserName
Selection.MoveRight Unit:=wdCell Selection.TypeText Text:=Now()
End Sub
Option Explicit
'api call for obtaining the username
Private Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long)
Public Function WindowsUserName() As String
' ---------------------------------------------
'Function to extract the name:
' ---------------------------------------------
Dim szBuffer As String * 100
Dim lBufferLen As Long
lBufferLen = 100
If CBool(GetUserName(szBuffer, lBufferLen)) Then
WindowsUserName = Left$(szBuffer, lBufferLen - 1)
Else
WindowsUserName = CStr(Empty)
End If
End Function
Private Sub CheckBox1_Click()
Selection.MoveRight Unit:=wdCell Selection.TypeText Text:=WindowsUserName
Selection.MoveRight Unit:=wdCell Selection.TypeText Text:=Now()
End Sub