View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
unplugs[_13_] unplugs[_13_] is offline
external usenet poster
 
Posts: 1
Default Question of Import Export Files

Thanks God! About my 5th question, I had found the thread...

Anyway, i got a question about it...

' Declare for call to mpr.dll.
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long

Const NoError = 0 'The Function call was successful

Sub GetUserName()

' Buffer size for the return string.
Const lpnLength As Integer = 255

' Get return buffer space.
Dim status As Integer

' For getting user information.
Dim lpName, lpUserName As String

' Assign the buffer size constant to lpUserName.
lpUserName = Space$(lpnLength + 1)

' Get the log-on name of the person using product.
status = WNetGetUser(lpName, lpUserName, lpnLength)

' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C ar
null-
' terminated. Strings in Visual Basic are no
null-terminated.
' The null character must be removed from the C strings to b
used
' cleanly in Visual Basic.
lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
Else

' An error occurred.
MsgBox "Unable to get the name."
End
End If

' Display the name of the person logged on to the machine.
MsgBox "Welcome " & lpUserName

End Sub


The above is the codes to get the user name....Anyway, can the usernam
placed in a cell? If can... How to do that? I want to placed th
username in sheet1 cell "G5".... Is there any method to do so?

and why I cannot put as:
Cells(NextRow,7) = & lpUserName
It gave me the error msg when I put "&" infront....

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