Solved

Change ShellAndWait to not wait

Posted on 2014-07-19
2
176 Views
Last Modified: 2014-07-20
So I have the following function that works great:

Public Sub ShellAndWait(ByVal program_name As String, _
                         Optional ByVal window_style As VbAppWinStyle = vbNormalFocus, _
                         Optional ByVal max_wait_seconds As Long = 0)
    Dim lngProcessId As Long
    Dim lngProcessHandle As Long
    Dim datStartTime As Date
    Dim lngCursor As Long
    Const WAIT_TIMEOUT = &H102
    Const SYNCHRONIZE As Long = &H100000
    Const INFINITE As Long = &HFFFFFFFF

    lngCursor = Screen.MousePointer
    'Screen.'MousePointer = vbHourglass
    ' Start the program.
    On Error GoTo ShellError
    lngProcessId = Shell(program_name, window_style)
    On Error GoTo 0
    
    DoEvents

    ' Wait for the program to finish.
    ' Get the process handle.
    lngProcessHandle = OpenProcess(SYNCHRONIZE, 0, lngProcessId)
    If lngProcessHandle <> 0 Then
        datStartTime = Now
        Do
          If WaitForSingleObject(lngProcessHandle, 250) <> WAIT_TIMEOUT Then
            Exit Do
          End If
          DoEvents
          If max_wait_seconds > 0 Then
            If DateDiff("s", datStartTime, Now) > max_wait_seconds Then Exit Do
          End If
        Loop
        CloseHandle lngProcessHandle
    End If
    Screen.MousePointer = lngCursor
    
    Exit Sub
    
ShellError:
End Sub

Open in new window


I would like to change it so that it does the same thing but doesn't wait for the process to finish.  I still want it to finish, but in the background.  

Any ideas?
0
Comment
Question by:hrolsons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Assisted Solution

by:duncanb7
duncanb7 earned 250 total points
ID: 40207156
At this link, http://www.cpearson.com/excel/ShellAndWait.aspx
it mentions you can use Shell function to do command and don't wait for the command complete. Is Shell function what your want. The ShellAndWait function is target to improve Shell function to wait the command finish before go to next step

Actually, you can use Shell function that can be programmed to wait or not wait for comand complete , you can find it at Wait option from MS manual at  http://msdn.microsoft.com/en-us/library/xe736fyk(v=vs.90).aspx

Hope understand your question. If not , please point it out

Duncan
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40207215
Simply call Shell alone instead of calling ShellAndWait:

Shell(program_name, window_style)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question