How to return the machine name?

M

Maury Markowitz

Hey everyone,

I'm back into VBA programming after a long hiatus, and this time I'm
on the Mac just to make things confusing and difficult to debug :)

My current problem is a simple one: we have a DB on a virtual server
and I'd like the VBA to only run when opened on that machine (via
RDP). Google fails to reveal an easy way to test if I'm running on a
particular machine - is there one?
 
G

GS

Maury Markowitz pretended :
Hey everyone,

I'm back into VBA programming after a long hiatus, and this time I'm
on the Mac just to make things confusing and difficult to debug :)

My current problem is a simple one: we have a DB on a virtual server
and I'd like the VBA to only run when opened on that machine (via
RDP). Google fails to reveal an easy way to test if I'm running on a
particular machine - is there one?

You could try...

If Not Environ("ComputerName") = <ServerName> Then _
ThisWorkbook.Close SaveChanges:=False

...where you substitute your actual server's computer name in the
(obvious) placeholder above.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
I

isabelle

Le 2012-04-27 15:51, GS a écrit :
Ron,
I gave that 'Mac' issue some thought and is why I opted for VBA's Environ() function.

yes GS, it is ok on xlxp,

MsgBox Environ("ComputerName")
 
I

isabelle

oups,

xlxp(hepl)
Non available for Macintosh.

--
isabelle



Le 2012-04-27 17:29, isabelle a écrit :
 
G

GS

It happens that Ron Rosenfeld formulated :
I have no experience with the Mac, as I wrote. But in HELP for the Environ
Function with my Excel 2007, it states that that function is not available on
the Macintosh.

I see that! Hmm.., probably a security thing? I guess it would depend
what OS is on the server the OP uses. His post suggests he is using a
Mac but does not clearly state the OS of the server Excel is running
on. However, I do know Mac users can run Windows on v10 and later...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
G

GS

I went to McGimpsey's site to see what I could find there for Mac.
==>nothing! I did see, though, that he runs Windows on his Mac in
Virtual PC.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
C

CellShocked

It happens that Ron Rosenfeld formulated :

I see that! Hmm.., probably a security thing? I guess it would depend
what OS is on the server the OP uses. His post suggests he is using a
Mac but does not clearly state the OS of the server Excel is running
on. However, I do know Mac users can run Windows on v10 and later...

Get the machine name via a terminal or other MAC method. Assign the
result as a variable name. Read that variable name from within Excel.
 
M

Maury Markowitz

  If Not Environ("ComputerName") = <ServerName> Then _
    ThisWorkbook.Close SaveChanges:=False

Looking over the thread…

The machine in question is a PC, a virtual "cloud server" to be exact.
My current model is to place a template file on the server, and ask
the user the open it there. As part of the scripts, it will created
and save out a new file (a simple one, no scripts) that can then be
opened on any Mac or PC.

So I think the Environ method should work for this purpose.

But the purpose of this call is to make sure they open it on the right
machine. If they don't, they get a warning. But I *suspect* that if
they were to open it on the Mac, the compiler would trip on the
Enviorn call and put up some nasty user-unfriendly message. Any ideas
on how to avoid this?
 
G

GS

Maury Markowitz formulated on Saturday :
Looking over the thread…

The machine in question is a PC, a virtual "cloud server" to be exact.
My current model is to place a template file on the server, and ask
the user the open it there. As part of the scripts, it will created
and save out a new file (a simple one, no scripts) that can then be
opened on any Mac or PC.

So I think the Environ method should work for this purpose.

But the purpose of this call is to make sure they open it on the right
machine. If they don't, they get a warning. But I *suspect* that if
they were to open it on the Mac, the compiler would trip on the
Enviorn call and put up some nasty user-unfriendly message. Any ideas
on how to avoid this?

You can use an error handler...

Sub Whatever()
'..Dim stuff

On Error GoTo errhandler 'Macs will choke on this
If Not Environ("ComputerName") = <computername> Then _
ThisWorkbook.Close SaveChanges:=False

'..Do stuff


normalexit:
Exit Sub

errhandler:
MsgBox "You can't use this template on this machine!"
End Sub

...assumes the stored project runs on the machine accessing the project
on the server.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top