Customer Center

Welcome back

My Account Logout
#4848

Ok found out how to determine if in Runtime or IDE in case anyone else wants to know that for some reason. You need to create a new module with the following code:

Option Explicit

Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long
Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (MyDest As Any, MySource As Any, ByVal MySize As Long)

Public Function CmdLineToStr() As String
'Returns the command line used to open Excel
    Dim Buffer() As Byte, StrLen As Long, CmdPtr As Long
    CmdPtr = GetCommandLine()
    If CmdPtr > 0 Then
      StrLen = lstrlenW(CmdPtr) * 2
      If StrLen > 0 Then
        ReDim Buffer(0 To (StrLen – 1)) As Byte
        CopyMemory Buffer(0), ByVal CmdPtr, StrLen
        CmdLineToStr = Buffer
      End If
    End If
End Function

Then in your automation use this to determine if it is run in IDE

Dim cmdlinepassed As String
cmdlinepassed = CmdLineToStr()
If InStr(1, cmdlinepassed, "BWSAgent.exe") > 0 Then
   'this should mean it is IDE???
   'seems like IDE has a BWSAgent commandline executable

Else
   'this means we should be in an automation!
    'seems like automation has a BWSRuntime.exe commandline executable
   Shutdown_
End If

Hope that helps some people. This way if in IDE you do not want something to happen or vice versa you can now do that.