Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default computer_name

Is there a simple "formula" for adding the computername to a cell without
resorting to a VBA macro.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"