Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2004, 02:58 PM
Registered User
 
Join Date: Jun 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to eric_winters Send a message via Yahoo to eric_winters
Default Use VBA to assign cell values

Hello All, thanks for reading this and helping a newbie out.

I have the need to use VBA to assign values to a cell based on a function that loads at the workbook open event. Any ideas?

Thanks, Eric

 
Old September 3rd, 2004, 10:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you be a bit more specific? What do you have and what do you want with it?
 
Old September 3rd, 2004, 02:27 PM
Registered User
 
Join Date: Jun 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to eric_winters Send a message via Yahoo to eric_winters
Default

I have found my solution:

I wanted this function:
' 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

To place the username value in a cell I am using:
Sheet1.Range("B1") = username()

So far it's working as expected.

Thanks,
Eric






Similar Threads
Thread Thread Starter Forum Replies Last Post
assign numerical values to text ptrussell2009 Excel VBA 9 October 8th, 2017 04:38 AM
Pull data values & assign them to a text control cesemj ASP.NET 2.0 Basics 0 March 12th, 2008 06:54 AM
c# and Excel cell values hardboiled C# 0 November 16th, 2007 11:12 AM
Assign 2 values to each Item in a Select Menu phungleon Classic ASP Databases 4 May 5th, 2004 06:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.