» Function for returning the computer name using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Custom Functions in VBA
VERSION - All Microsoft Excel Versions
The function below will return the computer name for the machine running the code, works in both Windows NT and Windows95/98.
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Function ReturnComputerName() As String
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetComputerName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen > 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnComputerName = UCase(Trim(tString))
End Function
Book Store:
Recommended Books:
- Financial Statement Analysis with S&P insert card
- The Intelligent Investor: The Definitive Book On Value Investing, Revised Edition
- Rich Dad, Poor Dad: What the Rich Teach Their Kids About Money--That the Poor and Middle Class Do Not!
- Treason: Liberal Treachery from the Cold War to the War on Terrorism
- H&R Block's Just Plain Smart(tm) Tax Planning Advisor: A year-round approach to lowering your taxes this year, next year and beyond
- Microsoft Excel 2002 Formulas (With CD-ROM)
No comments have been submitted.

