1

VBA (Outlook マクロ用) で ShellExecute を使用する方法は理解していますが、ShellExecuteEx を使用して、スクリプトで実行されたプログラムを待機できるようにしたいと考えています。誰かがこれを行う方法の例を持っていますか? 現在、私はこのコードを持っています:

Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3

Public Declare Function ShellExecute _
    Lib "shell32.dll" _
        Alias "ShellExecuteA" ( _
            ByVal Hwnd As Long, _
            ByVal lpOperation As String, _
            ByVal lpFile As String, _
            ByVal lpParameters As String, _
            ByVal lpDirectory As String, _
            ByVal nShowCmd As Long) _
As Long

'// Properties API
Private Type SHELLEXECUTEINFO
    cbSize       As Long
    fMask        As Long
    Hwnd         As Long
    lpVerb       As String
    lpFile       As String
    lpParameters As String
    lpDirectory  As String
    nShow        As Long
    hInstApp     As Long
    lpIDList     As Long
    lpClass      As String
    hkeyClass    As Long
    dwHotKey     As Long
    hIcon        As Long
    hProcess     As Long
End Type

Private Declare Function ShellExecuteEx _
    Lib "shell32.dll" ( _
        Prop As SHELLEXECUTEINFO) _
As Long

Public Function fnGetPropDlg(strFilepath As String) As Long
Dim Prop As SHELLEXECUTEINFO

With Prop
    .cbSize = Len(Prop)
    .fMask = &HC
    .Hwnd = 0&
    .lpVerb = "properties"
    .lpFile = strFilepath
End With

fnGetPropDlg = ShellExecuteEx(Prop)

End Function

次に、実際のプログラムを呼び出すコード (ShellExecute を使用):

RetVal = ShellExecute(0, "open", "C:\Documents and Settings\my\Desktop\zipTools.hta", "", "", SW_SHOWMAXIMIZED)

スクリプトの実行を続行する前に、ShellExecuteEx を使用して HTA が閉じられるのを待つことができるように、これを切り替える方法について誰か助けてもらえますか?

4

4 に答える 4

2

古い質問ですが、もっと簡単な答えがあります:

VBA シェル & 待機:簡単な方法!

Sub ShellAndWait(pathFile As String)
    With CreateObject("WScript.Shell")
        .Run pathFile, 1, True
    End With
End Sub

(1 行にまとめることもできますが、この方が読みやすいです。)


使用例:

Sub demo_Wait()
    ShellAndWait ("notepad.exe")
    Beep 'this won't run until Notepad window is closed
    MsgBox "Done!"
End Sub

Chip Pearson のサイト(およびその他のオプション) から適応。

于 2018-09-13T09:37:53.270 に答える
0

私が間違っていなければ、設定する必要があります

SEE_MASK_NOASYNC
fMask パラメータのビット。

Const SEE_MASK_NOASYNC As Long = &h0&
With Prop    
    .fMask = &HC Or SEE_MASK_NOASYNC
End With

編集

うーん、私もそれを機能させるのに苦労しています。GetFileInformationByHandle だけを検討しましたか?

于 2009-09-03T19:23:07.063 に答える