VBA, MS Access MS Access в примерах

Запуск Приложения (ShellExecute API)

#If VBA7 Then
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hwnd As LongPtr, _
        ByVal Operation As String, _
        ByVal Filename As String, _
        Optional ByVal Parameters As String, _
        Optional ByVal Directory As String, _
        Optional ByVal WindowStyle As Long = vbMinimizedFocus _
            ) As LongPtr
#Else
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal Operation As String, _
        ByVal Filename As String, _
        Optional ByVal Parameters As String, _
        Optional ByVal Directory As String, _
        Optional ByVal WindowStyle As Long = vbMinimizedFocus _
            ) As Long
#End If
'---------------------------------------------------------------------------------------------------
'https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-function
'The windowstyle named argument has these values:
'   vbHide              0   Window is hidden and focus is passed to the hidden window. The vbHide constant is not applicable on Macintosh platforms.
'   vbNormalFocus       1   Window has focus and is restored to its original size and position.
'   vbMinimizedFocus    2   Window is displayed as an icon with focus.
'   vbMaximizedFocus    3   Window is maximized with focus.
'   vbNormalNoFocus     4   Window is restored to its most recent size and position. The currently active window remains active.
'   vbMinimizedNoFocus  6   Window is displayed as an icon. The currently active window remains active.
'---------------------------------------------------------------------------------------------------


Примеры эксплуатации:


Private Sub ShellExecute_OpenFileInAssocApp()
Dim strPathOrURL As String
    strPathOrURL = "d:\Temp\Перенос папки Users.pdf"
    ShellExecute 0&, vbNullString, strPathOrURL, vbNullString, vbNullString, vbNormalFocus
End Sub


Private Sub ShellExecute_PrintFile(strFilePath As String) 'Печать:
   ShellExecute 0&, "Print", strFilePath, 0&, 0&, vbHide
End Sub
Назад ToTop
L.E. 11.04.2024
Рейтинг@Mail.ru