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?
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
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.
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.
Re: How to tell if you're running remotely
Quote:
Is there another way that I can be absolutely sure that I am running remotely?
a different login?
Re: How to tell if you're running remotely
I like si's suggestion. Thanks.
Re: How to tell if you're running remotely
Quote:
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)
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
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?