|
-
Jan 16th, 2014, 12:53 PM
#1
Thread Starter
Hyperactive Member
How to tell if you're running remotely
Maybe the wrong question, but here's the situation. I someimes develop VBA code and run Excel reports from home; i.e. remotely. The programs often SFTP data from a 3rd party server. If I am testing and running from home, I want to download data but not delete it from the 3rd party server. When the report is running in production mode, the data needs to be deleted after download.
In the past, I've used the computer name to decide whether the program should run test or production ( I check the name of the computer inside the VBA code). I know the name of the remote computers. The problem is that the remote computer names can change, and the computers running production off the server can change as well.
Is there another way that I can be absolutely sure that I am running remotely?
-
Jan 16th, 2014, 01:21 PM
#2
Re: How to tell if you're running remotely
Why not implement a command-line argument?
at home: excel.exe myfile.xlsm /e/remote
at work: excel.exe myfile.xlsm /e/work
and then it's just a question of catching the arguments in a select case or if else
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jan 16th, 2014, 01:51 PM
#3
Thread Starter
Hyperactive Member
Re: How to tell if you're running remotely
Good thought, but if users launched the Excel report by double clicking from Explorer, instead of via icon or button, I'd miss the arguments, right? Thanks.
-
Jan 16th, 2014, 02:09 PM
#4
Re: How to tell if you're running remotely
An alternative method is to create a text file in a specific place (the file contents don't matter), and if the file exists (which you can check using Dir) then treat it as testing mode.
-
Jan 16th, 2014, 03:21 PM
#5
Re: How to tell if you're running remotely
Is there another way that I can be absolutely sure that I am running remotely?
a different login?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 16th, 2014, 05:24 PM
#6
Thread Starter
Hyperactive Member
Re: How to tell if you're running remotely
I like si's suggestion. Thanks.
-
Jan 17th, 2014, 03:48 AM
#7
Re: How to tell if you're running remotely
 Originally Posted by doasidont
Good thought, but if users launched the Excel report by double clicking from Explorer, instead of via icon or button, I'd miss the arguments, right? Thanks.
In that case the commandline-arguments would be empty, which you could use as a kinda default-value equaling "at work"
Look here at post #3: http://www.vbforums.com/showthread.p...DKenny-is-KING
Just write a BAT-File with your command-line as above, save it on your desktop at home, and start from there.
In the workbook-open-event you just have to put an If-clause if the command-line is "/e/remote", If yes go to test-mode, everything else goes to production-mode
EDIT: After thinking a bit i'd do it along these lines, assuming the only difference between TestMode and ProductionMode is the not-deleting of the file on the server
Dim a public boolean-variable in a standard-module, something like "Public TestMode As Boolean"
The first line in the workbook-open-event would be "TestMode=False"
Then you call the GetCommandLine-Function as shown in the example
If MyCommandLine="/e/remote" Then TestMode=True
Somewhere in in your code you probably have a line calling the File-Deleting-on-the-server-Routine
You'd just have to change it to something like this:
If Not TestMode Then Call DeleteFileOnServer(MyFileName)
Last edited by Zvoni; Jan 17th, 2014 at 04:06 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jan 17th, 2014, 05:38 AM
#8
Re: How to tell if you're running remotely
getting the external ip address, should also tell if you are at the office or not
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 17th, 2014, 01:24 PM
#9
Re: How to tell if you're running remotely
Couldn't you go by the download location to determine if you need to delete teh data after or not?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|