Solved

PC Name fro Excel VBA

Posted on 2011-09-21
4
208 Views
Last Modified: 2012-05-12
Please is it possible to return a computer name from Excel VBA? If so how?

In advance , many thanks

Norman Mitchell
0
Comment
Question by:NormanMitchell
  • 2
4 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 36572879
This might work, it does for me at least:
MsgBox Environ$("computername")

Open in new window

0
 
LVL 10

Expert Comment

by:ukerandi
ID: 36573180
MsgBox Environ("computername")
0
 
LVL 10

Accepted Solution

by:
ukerandi earned 500 total points
ID: 36573198
Private Declare Function GetComputerName Lib "kernel32" _
        Alias "GetComputerNameA" ( _
        ByVal lpBuffer As String, _
        ByRef nSize As Long) As Long


Private Sub CommandButton1_Click()

MsgBox CompName()
End Sub




Public Property Get ComputerName() As String

  Dim stBuff As String * 255, lAPIResult As Long
  Dim lBuffLen As Long
 
  lBuffLen = 255
 
  lAPIResult = GetComputerName(stBuff, lBuffLen)
 
  If lBuffLen > 0 Then ComputerName = Left(stBuff, lBuffLen)

End Property
Public Function CompName() As String
  CompName = ComputerName
End Function
0
 

Author Closing Comment

by:NormanMitchell
ID: 36593415
Once again many thanks - you guys always come up trumps
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now