Public Enum actionType openfile printfile End Enum Public Const SW_SHOWNORMAL As Long = 1 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 Function ExecuteFile(fileName As String, action As actionType) ' action can be either "Openfile" or "Printfile". Dim sAction As String Select Case action Case 0 ' openfile sAction = "Open" Case 1 ' printfile sAction = "Print" End Select ShellExecute 0, sAction, fileName, vbNullString, "", SW_SHOWNORMAL End Function Sub TestPrint() ' open a file ExecuteFile "Chemin du fichier.txt", openfile ' print another ExecuteFile "Chemin du fichier.txt", printfile End Sub Private Sub CommandButton1_Click() TestPrint End Sub
Public Const SW_SHOWNORMAL = 1 Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByValhwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
X = ShellExecute(Me.hWnd, "Print", "C:\Test.txt", vbNullString, 0&, SW_SHOWNORMAL)
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByValhwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1 Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByValhwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionX = ShellExecute(Me.hWnd, "Print", "C:\Test.txt", vbNullString, 0&, SW_SHOWNORMAL)
Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private 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 Sub ImprimerFichier() Dim NomFichier As String Dim x As Long x = FindWindow("XLMAIN", Application.Caption) NomFichier = "Chemin du fichier.txt" ShellExecute x, "print", NomFichier, "", "", 1 End Sub Private Sub CommandButton1_Click() ImprimerFichier End Sub
x = FindWindow("XLMAIN", Application.Caption)