Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Log File using VBA in Excel XP or 97

I am trying to use VBA in an Auto_Open Macro in Excel XP. I am tryin
to log the username that is stored in the system registry under th
actual username and not just the application's username which may be
generic or blank name. Here's what I have:

Private Sub Workbook_Open()
LogInformation ThisWorkbook.Name & "; " & Now() & "; Opened By "
_
Application.UserName & "; Printer: "
Mid(Application.ActivePrinter, 12, 8)

End Sub
Sub LogInformation(LogMessage As String)

Const LogFileName As String = "P:\Rick\Lo
Files\Daily_Report\DailyReportLog.log"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if i
doesn't exist
Print #FileNum, LogMessage ' write information at the end of th
text file
Close #FileNum ' close the file

End Sub

Any ideas how to get the System User Name from the registry or an
other location?

Thanks,

Ric

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Log File using VBA in Excel XP or 97

From: Trevor Shuttleworth )
Subject: Code to show login name
Newsgroups: microsoft.public.excel.programming
Date: 2001-01-16 12:54:01 PST




Private Declare Function apiGetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long

Sub GetUserNameTest()
MsgBox fOSUserName
End Sub

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX < 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function

Regards

Trevor

--
Regards,
Tom Ogilvy

"rcweinbe " wrote in message
...
I am trying to use VBA in an Auto_Open Macro in Excel XP. I am trying
to log the username that is stored in the system registry under the
actual username and not just the application's username which may be a
generic or blank name. Here's what I have:

Private Sub Workbook_Open()
LogInformation ThisWorkbook.Name & "; " & Now() & "; Opened By " &
_
Application.UserName & "; Printer: " &
Mid(Application.ActivePrinter, 12, 8)

End Sub
Sub LogInformation(LogMessage As String)

Const LogFileName As String = "P:\Rick\Log
Files\Daily_Report\DailyReportLog.log"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if it
doesn't exist
Print #FileNum, LogMessage ' write information at the end of the
text file
Close #FileNum ' close the file

End Sub

Any ideas how to get the System User Name from the registry or any
other location?

Thanks,

Rick


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Log File using VBA in Excel XP or 97

The following VBA code uses an API call to get the Current User Name.
http://www.mvps.org/access/api/api0008.htm

The link is to "The Access Web", but it is by no means Access specific. It
works just fine in Excel.

--
George Nicholson

Remove 'Junk' from return address.


"rcweinbe " wrote in message
...
I am trying to use VBA in an Auto_Open Macro in Excel XP. I am trying
to log the username that is stored in the system registry under the
actual username and not just the application's username which may be a
generic or blank name. Here's what I have:

Private Sub Workbook_Open()
LogInformation ThisWorkbook.Name & "; " & Now() & "; Opened By " &
_
Application.UserName & "; Printer: " &
Mid(Application.ActivePrinter, 12, 8)

End Sub
Sub LogInformation(LogMessage As String)

Const LogFileName As String = "P:\Rick\Log
Files\Daily_Report\DailyReportLog.log"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if it
doesn't exist
Print #FileNum, LogMessage ' write information at the end of the
text file
Close #FileNum ' close the file

End Sub

Any ideas how to get the System User Name from the registry or any
other location?

Thanks,

Rick


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel file opens MS Excel Training Webpage When the Excel file ope JohnH Excel Discussion (Misc queries) 0 April 27th 10 03:32 PM
How to copy 2007 excel file formula results into a 2003 Excel file Nuria Alba de Luz Excel Discussion (Misc queries) 2 July 10th 09 01:48 PM
double click excel file on the desktop excel opens but not file? JPT4266 Excel Discussion (Misc queries) 3 May 7th 09 04:24 PM
Excel 2003: doubleclick on file opens Excel window, not file. Silvy Excel Discussion (Misc queries) 2 June 29th 06 12:15 PM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"