Solved

How to use shellwait not minimize the calling VBA

Posted on 2016-11-11
5
43 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
[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
  • 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 21

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 21
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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