• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 73
  • Last Modified:

How to use shellwait not minimize the calling VBA

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
rayluvs
Asked:
rayluvs
  • 3
  • 2
2 Solutions
 
rayluvsAuthor Commented:
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
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
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
 
rayluvsAuthor Commented:
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
 
rayluvsAuthor Commented:
Chouse our entry as assisted so member don't have the info without reading up.
0
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now