![]() |
How to return the machine name?
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? |
How to return the machine name?
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 |
How to return the machine name?
On Fri, 27 Apr 2012 11:15:39 -0700 (PDT), Maury Markowitz wrote:
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? In VBA on the PC, you can get that by a call to the kernel32.dll I don't know what the equivalent would be on the Mac, though. ==================== Option Explicit Private Declare Function GetComputerName Lib "kernel32.dll" _ Alias "GetComputerNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long Sub GetName() Dim lpBuff As String * 1313 GetComputerName lpBuff, Len(lpBuff) Debug.Print lpBuff End Sub =========================== |
How to return the machine name?
Ron,
I gave that 'Mac' issue some thought and is why I opted for VBA's Environ() function. -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
How to return the machine name?
On Fri, 27 Apr 2012 15:51:14 -0400, GS wrote:
Ron, I gave that 'Mac' issue some thought and is why I opted for VBA's Environ() function. 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. |
How to return the machine name?
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") -- isabelle |
How to return the machine name?
oups,
xlxp(hepl) Non available for Macintosh. -- isabelle Le 2012-04-27 17:29, isabelle a écrit : 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") |
How to return the machine name?
It happens that Ron Rosenfeld formulated :
On Fri, 27 Apr 2012 15:51:14 -0400, GS wrote: Ron, I gave that 'Mac' issue some thought and is why I opted for VBA's Environ() function. 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 |
How to return the machine name?
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 |
How to return the machine name?
On Fri, 27 Apr 2012 18:09:08 -0400, GS wrote:
It happens that Ron Rosenfeld formulated : On Fri, 27 Apr 2012 15:51:14 -0400, GS wrote: Ron, I gave that 'Mac' issue some thought and is why I opted for VBA's Environ() function. 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... 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. |
How to return the machine name?
On Apr 27, 3:33*pm, GS wrote:
* 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? |
How to return the machine name?
Maury Markowitz formulated on Saturday :
On Apr 27, 3:33Â*pm, GS wrote: Â* 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? 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 |
All times are GMT +1. The time now is 06:53 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com