ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   computer_name (https://www.excelbanter.com/excel-programming/364766-computer_name.html)

Simplefi

computer_name
 
Is there a simple "formula" for adding the computername to a cell without
resorting to a VBA macro.

Leith Ross[_583_]

computer_name
 

Hello Simplefi,

Not that I am aware of. The only method I have seen and used is a use
defined function that calls the Windows API. It is quite easy t
install and use. Here are the code and the directions to install th
API call and user defined function.

Installation Directions...
1) Copy the code in this post using CTRL+C
2) Open the Workbook the macro will be installed in.
3) Press ALT+F11 to launch the VBA Editor.
4) Press ALT+I to activate the Insert Menu
5) Press M to insert a new VBA module into the Workbook.
6) Press CTRL+V to paste the macro code into the module.
7) Press CTRL+S to save the Workbook changes

Using the Macro...
Simply use the Formula below in a cell to return the computr's name.

=ComputerName()


Code
-------------------

Declare Function GetComputerName _
Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Function ComputerName() As String

Dim CompName As String * 256
Dim RetVal

CompName = String(0, 256)
RetVal = GetComputerName(CompName, 256)
Chars = InStr(1, CompName, Chr$(0)) - 1

If Chars 0 Then
ComputerName = Left(CompName, Chars)
Else
ComputerName = ""
End If

End Function

-------------------


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=55344


Leith Ross[_584_]

computer_name
 

Hello Simplefi,

Not that I am aware of. The only method I have seen and used is a use
defined function that calls the Windows API. It is quite easy t
install and use. Here are the code and the directions to install th
API call and user defined function.

Installation Directions...
1) Copy the code in this post using CTRL+C
2) Open the Workbook the macro will be installed in.
3) Press ALT+F11 to launch the VBA Editor.
4) Press ALT+I to activate the Insert Menu
5) Press M to insert a new VBA module into the Workbook.
6) Press CTRL+V to paste the macro code into the module.
7) Press CTRL+S to save the Workbook changes

Using the Macro...
Simply use the Formula below in a cell to return the computr's name.

=ComputerName()


Code
-------------------

Declare Function GetComputerName _
Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Function ComputerName() As String

Dim CompName As String * 256
Dim RetVal

CompName = String(0, 256)
RetVal = GetComputerName(CompName, 256)
Chars = InStr(1, CompName, Chr$(0)) - 1

If Chars 0 Then
ComputerName = Left(CompName, Chars)
Else
ComputerName = ""
End If

End Function

-------------------


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=55344


Leith Ross[_585_]

computer_name
 

Hello Simplefi,

Not that I am aware of. The only method I have seen and used is a use
defined function that calls the Windows API. It is quite easy t
install and use. Here are the code and the directions to install th
API call and user defined function.

Installation Directions...
1) Copy the code in this post using CTRL+C
2) Open the Workbook the macro will be installed in.
3) Press ALT+F11 to launch the VBA Editor.
4) Press ALT+I to activate the Insert Menu
5) Press M to insert a new VBA module into the Workbook.
6) Press CTRL+V to paste the macro code into the module.
7) Press CTRL+S to save the Workbook changes

Using the Macro...
Simply use the Formula below in a cell to return the computr's name.

=ComputerName()


Code
-------------------

Declare Function GetComputerName _
Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Function ComputerName() As String

Dim CompName As String * 256
Dim RetVal

CompName = String(0, 256)
RetVal = GetComputerName(CompName, 256)
Chars = InStr(1, CompName, Chr$(0)) - 1

If Chars 0 Then
ComputerName = Left(CompName, Chars)
Else
ComputerName = ""
End If

End Function

-------------------


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=55344


Simplefi

computer_name
 
Leith,
thanks for reply. I'm going to have a play with your suggestion.
Below is code I put together last night - it does what I need.
The important bits being
..cells(Row...................
and
the system var Environ(..........

Best Regards
Simplefi

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
With Sheets("Sheet3")
.Select
.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Select
End With



Selection.Value = "Saved by " & Environ("UserName") & Date
Sheets("sheet1").Select


End Sub

"Leith Ross" wrote:


Hello Simplefi,

Not that I am aware of. The only method I have seen and used is a user
defined function that calls the Windows API. It is quite easy to
install and use. Here are the code and the directions to install the
API call and user defined function.

Installation Directions...
1) Copy the code in this post using CTRL+C
2) Open the Workbook the macro will be installed in.
3) Press ALT+F11 to launch the VBA Editor.
4) Press ALT+I to activate the Insert Menu
5) Press M to insert a new VBA module into the Workbook.
6) Press CTRL+V to paste the macro code into the module.
7) Press CTRL+S to save the Workbook changes

Using the Macro...
Simply use the Formula below in a cell to return the computr's name.

=ComputerName()


Code:
--------------------

Declare Function GetComputerName _
Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Function ComputerName() As String

Dim CompName As String * 256
Dim RetVal

CompName = String(0, 256)
RetVal = GetComputerName(CompName, 256)
Chars = InStr(1, CompName, Chr$(0)) - 1

If Chars 0 Then
ComputerName = Left(CompName, Chars)
Else
ComputerName = ""
End If

End Function

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=553447




All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com