Solved

How to use shellwait not minimize the calling VBA

Posted on 2016-11-11
5
16 Views
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?
0
Comment
Question by:rayluvs
  • 3
  • 2
5 Comments
 

Author Comment

by:rayluvs
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&
 Private Type STARTUPINFO
 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

Private Type PROCESS_INFORMATION
 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 _
 PROCESS_INFORMATION) As Long
    
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
 hObject As Long) As Long
    
Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
 Dim proc As PROCESS_INFORMATION
 Dim start As STARTUPINFO
 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

0
 
LVL 19

Accepted Solution

by:
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:

https://support.office.com/en-us/article/Shell-Function-ff2e4b1b-712d-4e34-aea6-6832eadd3c63
0
 

Assisted Solution

by:rayluvs
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
0
 

Author Closing Comment

by:rayluvs
ID: 41886336
Chouse our entry as assisted so member don't have the info without reading up.
0
 
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"
or
Call MsgBox ("my message",, "my title")
or
If MsgBox ("my message", vbYesNo, "my title") = vbYes then
0

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://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/A_3887-Getting-your-EE-Ranking-statistics-in-Excel-The-Next-Generation.html (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 (https://www.paessler.com/prtg). 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 http://bit.ly/XDcourse.

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