Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PC Name fro Excel VBA

Posted on 2011-09-21
4
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

704 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