![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Calgary
Posts: 57
|
I am trying to use this piece of code:
http://www.chrisrae.com/vba/routines/getusername.html ' By Chris Rae, 14/6/99, 3/9/00. Option Explicit ' This is used by GetUserName() to find the current user's ' name from the API Declare Function Get_User_Name Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long Function GetUserName() As String Dim lpBuff As String * 25 Get_User_Name lpBuff, 25 GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) End Function When i try to access it by calling the GetUserName, i am getting an error stating: "Compile Error: Constants, Fixed-Length Strings, Arrays, and Declare statements are not allowed as Public members of object modules" Can someone give me a heads up? Thanks. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Works fine for me. Did you paste it in an empty module ? The "Option Explicit" and "Declare Function" should be at the top (If you're not pasting to an empty module)
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Calgary
Posts: 57
|
I tried using it in a clean workbook...pasted it in and then tried to compile it...same error.
The Option and Declare are in the (Declarations) section at the top. |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
I pasted it into my workbook and it worked also.
|
|
|
|
|
|
#5 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Quote:
HTH _________________ [b] Mark O'Brien [ This Message was edited by: Mark O'Brien on 2002-02-26 13:21 ] |
|
|
|
|
|
|
#6 | |
|
Board Regular
Join Date: Feb 2002
Location: Calgary
Posts: 57
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|