How to use shellwait not minimize the calling VBA

Posted on 2016-11-11
Last Modified: 2016-11-14
We have VBA that uses shellwait; It does it's function as supposes to, call the apps/wait/return control to the next line.  Howver, the shellwait when return control to the next line, it minimize the windows the shellwait was called.

We want not to minimize.

How can we do this?
Question by:rayluvs
  • 3
  • 2

Author Comment

ID: 41884344
Oops! Forgot to include the shellwait code we  use...

Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)

'Rutine para crear todo para usar SHELLWAIT
 Private Const NORMAL_PRIORITY_CLASS = &H20&
 Private Const INFINITE = -1&
 cb As Long
 lpReserved As String
 lpDesktop As String
 lpTitle As String
 dwX As Long
 dwY As Long
 dwXSize As Long
 dwYSize As Long
 dwXCountChars As Long
 dwYCountChars As Long
 dwFillAttribute As Long
 dwFlags As Long
 wShowWindow As Integer
 cbReserved2 As Integer
 lpReserved2 As Long
 hStdInput As Long
 hStdOutput As Long
 hStdError As Long
End Type

 hProcess As Long
 hThread As Long
 dwProcessID As Long
 dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
 hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
 lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
 lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
 ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
 ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
 lpStartupInfo As STARTUPINFO, lpProcessInformation As _
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
 hObject As Long) As Long
Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
 Dim ret As Long
'Initialize the STARTUPINFO structure:
 With start
     .cb = Len(start)
     If Not IsMissing(WindowStyle) Then
         .dwFlags = STARTF_USESHOWWINDOW
         .wShowWindow = WindowStyle
     End If
 End With
'Start the shelled application:
 ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
         NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'Wait for the shelled application to finish:
 ret& = WaitForSingleObject(proc.hProcess, INFINITE)
 ret& = CloseHandle(proc.hProcess)
End Sub

Open in new window

LVL 19

Accepted Solution

crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41884451
here is your declaration for ShellWait:
Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)

When you call ShellWait, you can send the window style you desire as an optional paramater.  Here is a Microsoft reference page with choices you can pick:

Assisted Solution

rayluvs earned 0 total points
ID: 41886332
Thanx!! Didn't quite understand. but found it: it's vbNormalNoFocus

So for any member that may come with problem and don't want to read, the line should read:

ShellWait (pathname-app-arguments), vbNormalNoFocus

Author Closing Comment

ID: 41886336
Chouse our entry as assisted so member don't have the info without reading up.
LVL 19
ID: 41886676
you're welcome ~ happy to help

actually, the close parenthesis goes AFTER all the arguments ;)
... IF you preface it with Call
If not, no parentheses are used around the arguments since this is a Sub, not a Function that returns a value that can be handled.

here is an example:

MsgBox "my message",, "my title"
Call MsgBox ("my message",, "my title")
If MsgBox ("my message", vbYesNo, "my title") = vbYes then

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The code described here does no longer work. Please see replacement Article: (http…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now