' How to Tell if you are Running in the IDE
'
' Using the App object and the GetModuleFileName API
' to determine if you are running in the IDE.
'
' Jon Vote
'
' 02/2002
'
' 1) Create a new project. Form1 will be created by default.
' 2) Add a Command Button to the Form.
' 3) Paste the following code into the declarations section of Form1:
' --- Begin code for Form1
'How to tell if your program is running in the IDE
'
'Jon Vote, Idioma Software Inc.
'
'02/2002
'
'www.idioma-software.com
Option Explicit
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Sub Command1_Click()
MsgBox "Running in IDE? " & RunninInIDE
End Sub
Private Sub Form_Load()
Me.Caption = "How to tell if running in the IDE"
Command1.Caption = "&Test"
End Sub
'RunningInIDE - Returns TRUE if running in IDE, else FALSE
Private Function RunninInIDE() As Boolean
'This routine compares the path name returned by GetModuleFileName
'with App.Path & App.ExeName. If they are the same, the .exe is running.
'If not, you are running in the IDE.
Dim strModulePath As String
Dim strAppPath As String
Dim lngCount As Long
strModulePath = String(1000, 0)
lngCount = GetModuleFileName(App.hInstance, strModulePath, 1000)
strModulePath = Left(strModulePath, lngCount)
strAppPath = App.Path & "\" & App.EXEName & ".exe"
Debug.Print "Module Path: " & strModulePath
Debug.Print "App Path: " & strAppPath
If StrComp(strModulePath, strAppPath, vbTextCompare) = 0 Then
RunninInIDE = False
Else
RunninInIDE = True
End If
End Function
' --- End code for Form1 ---