Solved

PC Name fro Excel VBA

Posted on 2011-09-21
4
245 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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 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