Computer name

A

art

Hello:

Does anybody know how to display through a formula or vba the computer name
in excel 2007?
And what about the Windows product ID?
Please let me know.
 
R

Rick Rothstein \(MVP - VB\)

Using VBA... you can get the computer name with this function call...

CN = Environ("ComputerName")

What do you expect the product ID to look like? I'm guessing the value from
this property call is not what you are looking for?

PC = Application.ProductCode

Rick
 
R

Rick Rothstein \(MVP - VB\)

The statements I posted are the "full code" and assume you are assigning the
computer name to the variable CN and assigning the Product Code (which may
or may not be what you intended when you said "product ID") to the variable
PC... just assign them to your own variables instead.

Perhaps this will help you see what is going on. Type this statement in the
Immediate window and hit the Return key...

MsgBox Environ("ComputerName")

Now do the same for this statement...

MsgBox Application.ProductCode

Rick
 
A

art

It doesnt work. Can you send me the full code? HOw do I enter it in a module?
just MsgBox Environ("ComputerName")? And how Do I use the formula after
wards?

P.S. the product ID I meant was another way I want to identify the computer
instead of using the computer name.

Thanks
 
R

Rick Rothstein \(MVP - VB\)

Actually, the code does work, but I am thinking you are not as familiar with
VBA coding as your original posting may have suggested. Here are the steps
you can take to see the computer's name... From any worksheet, right click
the tab at the bottom of the worksheet and select View Code. Copy/Paste this
code into the window that appeared when you did this...

Sub SeeComputerName()
MsgBox "My computer's name: " & Environ("ComputerName")
End Sub

Now, go back to your worksheet, press Alt+F8 and select the SeeComputerName
item from the list that appears and click the Run button. Now, since
implementing this basic code cause you problems, I am going to suggest you
read up on creating macros before you continue trying to do more complicated
programming. Check out this link as a starter...

http://www.anthony-vba.kefra.com/index_011.htm

(start with the 3 basic tutorials) and, perhaps, buying a basic Excel VBA
book to read might be helpful also.

Rick
 
A

art

How can I get this result in a formula?

Sub MyprodID()
MsgBox "My ProgID is " & _
Application.COMAddIns(1).progID & _
" and my GUID is " & _
Application.COMAddIns(1).GUID
End Sub


That means I should have the formula to be able to see the same results as
in the msg box?
 
R

Rick Rothstein \(MVP - VB\)

I really do not think those properties are what you want... on my system
they return the AddIn name and GUID for my Dymo Label printer. In any event,
assuming you really do want them (or if you find what you actually want
later on), the method to be able to display these results in a cell on a
worksheet using a formula (known as a User Defined Function or UDF for
short) in the cell is as follows. Go into the VB editor and put the
following code in a Module (get the Module the same way I told you on one of
your other posts in another newsgroup... click Insert/Module from the VB
editor's menu bar)...

Function GetProgIDs()
GetProgIDs = Application.COMAddIns(1).progID & " -- " & _
Application.COMAddIns(1).GUID
End Function

Now, back on your worksheet, type this into any cell....

=GetProgIDs()

(the parentheses are required) and the information you asked about will be
displayed in the cell.

Rick
 
Top