Option Explicit
Private Declare Function FindWindowA& Lib "User32" _
(ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function EnableWindow& Lib "User32" _
(ByVal hWnd&, ByVal bEnable&)
Private Declare Function GetWindowLongA& Lib "User32" _
(ByVal hWnd&, ByVal nIndex&)
Private Declare Function SetWindowLongA& Lib "User32" _
(ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Const HWND_BROADCAST = &HFFFF
Const WM_WININICHANGE = &H1A
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetWindowsDirectory Lib "Kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Dim Chemin As String
Dim NC As Long
Dim Ret As String
Dim Imprdef
Private Sub UserForm_Initialize()
ComboBox1.AddItem "HP Color LaserJet 1600"
ComboBox1.AddItem "PDFCreator"
ComboBox1.AddItem "CutePDF Writer"
Dim hWnd As Long
hWnd = FindWindowA(vbNullString, Me.Caption)
SetWindowLongA hWnd, -16, GetWindowLongA(hWnd, -16) Or &H20000
End Sub
Private Sub UserForm_Activate()
Dim hWnd As Long
hWnd = FindWindowA("XLMAIN", Application.Caption)
EnableWindow hWnd, 1
End Sub
Private Sub ProcédureImPrimanteParDéfaut(Imprdef)
ChangeImprimanteParDéfaut (Imprdef)
End Sub
Private Sub CommandButton1_Click()
Imprdef = ComboBox1
ProcédureImPrimanteParDéfaut (Imprdef)
Application.Dialogs(xlDialogPrint).Show
End Sub
Sub ChangeImprimanteParDéfaut(nom As String)
Chemin = String(260, 0)
Chemin = Left$(Chemin, GetWindowsDirectory(Chemin, Len(Chemin))) + "\win.ini"
Ret = String(255, 0)
NC = GetPrivateProfileString("Devices", nom, "", Ret, 255, Chemin)
Ret = Left(Ret, NC)
WritePrivateProfileString "windows", "device", nom & "," & Ret, Chemin
SendMessage HWND_BROADCAST, WM_WININICHANGE, 0, "windows"
With Sheets("Feuil1").PageSetup
.PaperSize = xlPaperA4
.Orientation = xlLandscape ' mode paysage
'.Orientation = xlPortrait 'mode portrait
.Zoom = 100
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Application.DisplayAlerts = False
ActiveWorkbook.Save
End Sub