Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign cell value from VBA function

Hello,

Please help out a newbie. How can I assign a cell value from a VBA
function? I have the following in my VBA code:
Private Sub Workbook_Open()
MsgBox username()
End Sub


' Return the user's name.
Public Function username() As String
Const UNLEN = 256 ' Max user name length.
Dim user_name As String
Dim name_len As Long

user_name = Space$(UNLEN + 1)
name_len = Len(user_name)
If GetUserName(user_name, name_len) = 0 Then
username = "<unknown"
Else
username = Left$(user_name, name_len - 1)
End If
End Function


This works fine for displaying the Msgbox, but I'd like to put the
username in a specific spreadsheet cell.

Any help is appreciated.
Eric
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign cell value from VBA function

instead of
MsgBox username()
put
ActiveSheet.Range("A1") = username()


- Manges

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Assign cell value from VBA function

Eric,

Just type:

=username()

in the cell.

HTH,
Nikos

"easy_forshezee" wrote in message
om...
Hello,

Please help out a newbie. How can I assign a cell value from a VBA
function? I have the following in my VBA code:
Private Sub Workbook_Open()
MsgBox username()
End Sub


' Return the user's name.
Public Function username() As String
Const UNLEN = 256 ' Max user name length.
Dim user_name As String
Dim name_len As Long

user_name = Space$(UNLEN + 1)
name_len = Len(user_name)
If GetUserName(user_name, name_len) = 0 Then
username = "<unknown"
Else
username = Left$(user_name, name_len - 1)
End If
End Function


This works fine for displaying the Msgbox, but I'd like to put the
username in a specific spreadsheet cell.

Any help is appreciated.
Eric



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Assign cell value from VBA function

Eric,

Just type:

=username()

in the cell.

HTH,
Nikos

"easy_forshezee" wrote in message
om...
Hello,

Please help out a newbie. How can I assign a cell value from a VBA
function? I have the following in my VBA code:
Private Sub Workbook_Open()
MsgBox username()
End Sub


' Return the user's name.
Public Function username() As String
Const UNLEN = 256 ' Max user name length.
Dim user_name As String
Dim name_len As Long

user_name = Space$(UNLEN + 1)
name_len = Len(user_name)
If GetUserName(user_name, name_len) = 0 Then
username = "<unknown"
Else
username = Left$(user_name, name_len - 1)
End If
End Function


This works fine for displaying the Msgbox, but I'd like to put the
username in a specific spreadsheet cell.

Any help is appreciated.
Eric



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
Can I Assign A User Defined Function To A Cell? smartin Excel Worksheet Functions 0 June 28th 09 10:25 PM
Assign the cell address with a function T.Mad Excel Worksheet Functions 5 February 9th 07 03:21 AM
Assign commands to function keys Gerry Excel Discussion (Misc queries) 4 August 8th 05 05:14 PM
Assign Specific Function to Shortcut CA_Becker Excel Worksheet Functions 2 April 8th 05 05:53 PM
Assign Macro function not working Todd Huttenstine Excel Programming 1 April 2nd 04 08:31 PM


All times are GMT +1. The time now is 11:55 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"