TheSwamp

Code Red => VB(A) => Topic started by: A_LOTA_NOTA on August 17, 2007, 07:56:21 PM

Title: set focus
Post by: A_LOTA_NOTA on August 17, 2007, 07:56:21 PM
Could this be done?

In VBA, you could check for # of instances of Acad, then set focus to second instance, close dwg, and open in first instance. The button would work in either one. Pseudo thinking out loud...
http://www.theswamp.org/index.php?topic=18241.msg222653#msg222653

Title: Re: set focus
Post by: Keith™ on August 17, 2007, 08:44:44 PM
You can, but it is not as simple as it sounds. To check for the number of instances of AutoCAD, you would need to use API calls, then you would need to be able to reference the application in order to do what is suggested. It is not impossible, but it is somewhat complex.
Title: Re: set focus
Post by: A_LOTA_NOTA on August 17, 2007, 11:27:16 PM
Thanks Keith
Title: Re: set focus
Post by: Guest on August 20, 2007, 01:08:45 PM
Here's a start.  This will print on the Immediate window the number of instances running.

Code: [Select]
Public Sub HowManyAcads()
    Debug.Print TallyPrograms("acad.exe")
End Sub


Private Function TallyPrograms(ByRef EXEName As String)
    Dim cmd As String
    cmd = "SELECT * FROM Win32_Process WHERE Name='" & EXEName & "'"
    TallyPrograms = GetObject("winmgmts:").ExecQuery(cmd).Count
End Function
Title: Re: set focus
Post by: Bryco on August 20, 2007, 08:51:20 PM
It's a keeper Matt. Cheers.