Two methods, one for .NET (Visual Basic, but easily adjusted for C#) and the other for VB Classic (VB 5 and 6)

To check and see if the .NET code is running from the IDE:

More specifically, the .NET method checks to see if there is a debugger attached.  It is possible to attach a debugger to a compiled exe, so this would return True.

<code>
  If System.Diagnostics.Debugger.IsAttached Then
    ‘This is a way to see if we are running in the IDE. 

  End If
</code>

And, if you’re using VB Classic, you can use this:

<code>
‘Since Debug commands are compiled OUT, this will never return an error
‘when the code is compiled.
Private Function IsDebugMode as Boolean
  On Error Resume Next
  Debug.Assert 1/0
  IsDebugMode = (Err.Number <> 0)
  On Error Goto 0
End Function
</code>