View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default VBA - createobject - If

Hello guys,

I need some help with this algorithm in VBA (createobject). My function
should open a instance of my program if the program is already open it
don't have to open it again. The problem is that this function open the
program twice, trice ... so on. Could someone help me on that

' I have this function to Open a program
Function OpenPHObject() As Object


Dim oExec As Object
Dim WshShell As Object
Dim bolPack As Boolean

' I set up a Object
Set WshShell = CreateObject("Wscript.Shell")

'if the program is not open, open it
If Err < 0 Then
Set oExec = WshShell.Exec("C:\Program Files\PH\PH.exe")
bolPack = True

Else
Msgbox "the program is open"

End If

DoEvents

On Error Resume Next

'Call the function as argument the Program object
Set OpenPHObject = oExec



errorHandler:
MsgBox Err.Number & " " & Err.Description


End Function