Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant la
"vue avant impression" et ensuite un msgbox pour valider l'impression. Ce
qui suit ne fonctionne pas ! Si je fais une macro en enregistrement
automatique, je ne vois pas de trace de "fermer" après "vue avant
impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant la
"vue avant impression" et ensuite un msgbox pour valider l'impression. Ce
qui suit ne fonctionne pas ! Si je fais une macro en enregistrement
automatique, je ne vois pas de trace de "fermer" après "vue avant
impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant la
"vue avant impression" et ensuite un msgbox pour valider l'impression. Ce
qui suit ne fonctionne pas ! Si je fais une macro en enregistrement
automatique, je ne vois pas de trace de "fermer" après "vue avant
impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant la
"vue avant impression" et ensuite un msgbox pour valider l'impression. Ce
qui suit ne fonctionne pas ! Si je fais une macro en enregistrement
automatique, je ne vois pas de trace de "fermer" après "vue avant
impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant la
"vue avant impression" et ensuite un msgbox pour valider l'impression. Ce
qui suit ne fonctionne pas ! Si je fais une macro en enregistrement
automatique, je ne vois pas de trace de "fermer" après "vue avant
impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant la
"vue avant impression" et ensuite un msgbox pour valider l'impression. Ce
qui suit ne fonctionne pas ! Si je fais une macro en enregistrement
automatique, je ne vois pas de trace de "fermer" après "vue avant
impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Copie d'un précédent message.
Ce code permet d'intercepter les différents boutons de l'aperçu avant
impression.
A manier avec précaution.
Pour ton timer de 2 secondes, "il suffit de le lancer puis de
l'intercepter aux moments adéquats à l'aide des API SetTimer et
KillTimer".
Bon week-end du 15 au 30 Octobre(peut être 2006).
Alain CROS
'--------Début de copie
Bonjour.
J'ai peur que ce soit un peu compliqué!
Oui, le wParam sert à indiquer le bouton.
Le code suivant intercepte tous les boutons de l'apperçu sauf le
bouton Fermer.
Si ça t'intéresse, c'est le 8.
Je ne l'ai pas codé, car je n'arrive pas à en sortir proprement.
C'est simplifiable en l'état mais j'ai laissé une Proc par bouton
pour comprendre le principe.
Il manque encore beaucoup de lignes de code pour obtenir quelque
chose qui tienne la route.
Bonne chance !
Alain CROS
'--------
Dans un module:
Private Declare Function SetWindowsHookEx& _
Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _
Lib "kernel32" _
()
Private Declare Function GetParent& _
Lib "user32" _
(ByVal hwnd&)
Private Declare Function UnhookWindowsHookEx& _
Lib "user32" _
(ByVal hHook&)
Private Declare Function SetWindowLong& _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function GetDlgItem& _
Lib "user32" _
(ByVal hDlg&, ByVal nIDDlgItem&)
Private Declare Function GetWindowText& _
Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd&, ByVal lpString$, ByVal cch&)
Private Declare Function CallWindowProc& _
Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc&, ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&)
Private LeHook&, OldWinProcSuiv&, OldWinProcPrec&, _
OldWinProcZoom&, OldWinProcImp&, OldWinProcPage&, _
OldWinProcMarge&, OldWinProcSaut&, OldWinProcAide&
Sub ApercuAvantImpression()
Const WH_CBT& = &H5
LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&,
GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show
End Sub
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&)
Const GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9&
Dim hwnd&
If lMsg = HCBT_SETFOCUS Then
hwnd = GetParent(wParam)
UnhookWindowsHookEx LeHook
OldWinProcSuiv = SetWindowLong(GetDlgItem(hwnd, 0&),
GWL_WNDPROC, AddressOf SuivProc) OldWinProcPrec > SetWindowLong(GetDlgItem(hwnd, 1&), GWL_WNDPROC, AddressOf
PrecProc) OldWinProcZoom = SetWindowLong(wParam, GWL_WNDPROC,
AddressOf ZoomProc) OldWinProcImp > SetWindowLong(GetDlgItem(hwnd, 3&), GWL_WNDPROC, AddressOf
ImpProc) OldWinProcPage = SetWindowLong(GetDlgItem(hwnd, 4&),
GWL_WNDPROC, AddressOf PageProc) OldWinProcMarge > SetWindowLong(GetDlgItem(hwnd, 5&), GWL_WNDPROC, AddressOf
MargeProc) OldWinProcSaut = SetWindowLong(GetDlgItem(hwnd, 6&),
GWL_WNDPROC, AddressOf SautProc) OldWinProcAide > SetWindowLong(GetDlgItem(hwnd, 9&), GWL_WNDPROC, AddressOf AideProc)
End If
End Function
Private Function SuivProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcSuiv
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
SuivProc = CallWindowProc(OldWinProcSuiv, hwnd, Msg, wParam,
lParam)
End Function
Private Function PrecProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcPrec
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
PrecProc = CallWindowProc(OldWinProcPrec, hwnd, Msg, wParam,
lParam)
End Function
Private Function ZoomProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcZoom
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
ZoomProc = CallWindowProc(OldWinProcZoom, hwnd, Msg, wParam,
lParam)
End Function
Private Function ImpProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcImp
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
ImpProc = CallWindowProc(OldWinProcImp, hwnd, Msg, wParam, lParam)
End Function
Private Function PageProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcPage
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
PageProc = CallWindowProc(OldWinProcPage, hwnd, Msg, wParam,
lParam)
End Function
Private Function MargeProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcMarge
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
MargeProc = CallWindowProc(OldWinProcMarge, hwnd, Msg, wParam,
lParam)
End Function
Private Function SautProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcSaut
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
SautProc = CallWindowProc(OldWinProcSaut, hwnd, Msg, wParam,
lParam)
End Function
Private Function AideProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcAide
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
AideProc = CallWindowProc(OldWinProcAide, hwnd, Msg, wParam,
lParam)
End Function
Private Function TitreDeFenetre$(hwnd&)
TitreDeFenetre = Space$(50&)
TitreDeFenetre = Left$(TitreDeFenetre, GetWindowText(hwnd,
TitreDeFenetre, 50&))
End Function
'--------Fin de copie
"j-pascal" a écrit dans le message de news:
upy#Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant
la "vue avant impression" et ensuite un msgbox pour valider
l'impression. Ce qui suit ne fonctionne pas ! Si je fais une macro
en enregistrement automatique, je ne vois pas de trace de "fermer"
après "vue avant impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Copie d'un précédent message.
Ce code permet d'intercepter les différents boutons de l'aperçu avant
impression.
A manier avec précaution.
Pour ton timer de 2 secondes, "il suffit de le lancer puis de
l'intercepter aux moments adéquats à l'aide des API SetTimer et
KillTimer".
Bon week-end du 15 au 30 Octobre(peut être 2006).
Alain CROS
'--------Début de copie
Bonjour.
J'ai peur que ce soit un peu compliqué!
Oui, le wParam sert à indiquer le bouton.
Le code suivant intercepte tous les boutons de l'apperçu sauf le
bouton Fermer.
Si ça t'intéresse, c'est le 8.
Je ne l'ai pas codé, car je n'arrive pas à en sortir proprement.
C'est simplifiable en l'état mais j'ai laissé une Proc par bouton
pour comprendre le principe.
Il manque encore beaucoup de lignes de code pour obtenir quelque
chose qui tienne la route.
Bonne chance !
Alain CROS
'--------
Dans un module:
Private Declare Function SetWindowsHookEx& _
Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _
Lib "kernel32" _
()
Private Declare Function GetParent& _
Lib "user32" _
(ByVal hwnd&)
Private Declare Function UnhookWindowsHookEx& _
Lib "user32" _
(ByVal hHook&)
Private Declare Function SetWindowLong& _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function GetDlgItem& _
Lib "user32" _
(ByVal hDlg&, ByVal nIDDlgItem&)
Private Declare Function GetWindowText& _
Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd&, ByVal lpString$, ByVal cch&)
Private Declare Function CallWindowProc& _
Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc&, ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&)
Private LeHook&, OldWinProcSuiv&, OldWinProcPrec&, _
OldWinProcZoom&, OldWinProcImp&, OldWinProcPage&, _
OldWinProcMarge&, OldWinProcSaut&, OldWinProcAide&
Sub ApercuAvantImpression()
Const WH_CBT& = &H5
LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&,
GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show
End Sub
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&)
Const GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9&
Dim hwnd&
If lMsg = HCBT_SETFOCUS Then
hwnd = GetParent(wParam)
UnhookWindowsHookEx LeHook
OldWinProcSuiv = SetWindowLong(GetDlgItem(hwnd, 0&),
GWL_WNDPROC, AddressOf SuivProc) OldWinProcPrec > SetWindowLong(GetDlgItem(hwnd, 1&), GWL_WNDPROC, AddressOf
PrecProc) OldWinProcZoom = SetWindowLong(wParam, GWL_WNDPROC,
AddressOf ZoomProc) OldWinProcImp > SetWindowLong(GetDlgItem(hwnd, 3&), GWL_WNDPROC, AddressOf
ImpProc) OldWinProcPage = SetWindowLong(GetDlgItem(hwnd, 4&),
GWL_WNDPROC, AddressOf PageProc) OldWinProcMarge > SetWindowLong(GetDlgItem(hwnd, 5&), GWL_WNDPROC, AddressOf
MargeProc) OldWinProcSaut = SetWindowLong(GetDlgItem(hwnd, 6&),
GWL_WNDPROC, AddressOf SautProc) OldWinProcAide > SetWindowLong(GetDlgItem(hwnd, 9&), GWL_WNDPROC, AddressOf AideProc)
End If
End Function
Private Function SuivProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcSuiv
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
SuivProc = CallWindowProc(OldWinProcSuiv, hwnd, Msg, wParam,
lParam)
End Function
Private Function PrecProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcPrec
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
PrecProc = CallWindowProc(OldWinProcPrec, hwnd, Msg, wParam,
lParam)
End Function
Private Function ZoomProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcZoom
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
ZoomProc = CallWindowProc(OldWinProcZoom, hwnd, Msg, wParam,
lParam)
End Function
Private Function ImpProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcImp
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
ImpProc = CallWindowProc(OldWinProcImp, hwnd, Msg, wParam, lParam)
End Function
Private Function PageProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcPage
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
PageProc = CallWindowProc(OldWinProcPage, hwnd, Msg, wParam,
lParam)
End Function
Private Function MargeProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcMarge
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
MargeProc = CallWindowProc(OldWinProcMarge, hwnd, Msg, wParam,
lParam)
End Function
Private Function SautProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcSaut
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
SautProc = CallWindowProc(OldWinProcSaut, hwnd, Msg, wParam,
lParam)
End Function
Private Function AideProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcAide
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
AideProc = CallWindowProc(OldWinProcAide, hwnd, Msg, wParam,
lParam)
End Function
Private Function TitreDeFenetre$(hwnd&)
TitreDeFenetre = Space$(50&)
TitreDeFenetre = Left$(TitreDeFenetre, GetWindowText(hwnd,
TitreDeFenetre, 50&))
End Function
'--------Fin de copie
"j-pascal" <nospam-j-pascal@free.fr> a écrit dans le message de news:
upy#o4V0FHA.2312@TK2MSFTNGP14.phx.gbl...
Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant
la "vue avant impression" et ensuite un msgbox pour valider
l'impression. Ce qui suit ne fonctionne pas ! Si je fais une macro
en enregistrement automatique, je ne vois pas de trace de "fermer"
après "vue avant impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP
Copie d'un précédent message.
Ce code permet d'intercepter les différents boutons de l'aperçu avant
impression.
A manier avec précaution.
Pour ton timer de 2 secondes, "il suffit de le lancer puis de
l'intercepter aux moments adéquats à l'aide des API SetTimer et
KillTimer".
Bon week-end du 15 au 30 Octobre(peut être 2006).
Alain CROS
'--------Début de copie
Bonjour.
J'ai peur que ce soit un peu compliqué!
Oui, le wParam sert à indiquer le bouton.
Le code suivant intercepte tous les boutons de l'apperçu sauf le
bouton Fermer.
Si ça t'intéresse, c'est le 8.
Je ne l'ai pas codé, car je n'arrive pas à en sortir proprement.
C'est simplifiable en l'état mais j'ai laissé une Proc par bouton
pour comprendre le principe.
Il manque encore beaucoup de lignes de code pour obtenir quelque
chose qui tienne la route.
Bonne chance !
Alain CROS
'--------
Dans un module:
Private Declare Function SetWindowsHookEx& _
Lib "user32" Alias "SetWindowsHookExA" _
(ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&)
Private Declare Function GetCurrentThreadId& _
Lib "kernel32" _
()
Private Declare Function GetParent& _
Lib "user32" _
(ByVal hwnd&)
Private Declare Function UnhookWindowsHookEx& _
Lib "user32" _
(ByVal hHook&)
Private Declare Function SetWindowLong& _
Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function GetDlgItem& _
Lib "user32" _
(ByVal hDlg&, ByVal nIDDlgItem&)
Private Declare Function GetWindowText& _
Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd&, ByVal lpString$, ByVal cch&)
Private Declare Function CallWindowProc& _
Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc&, ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&)
Private LeHook&, OldWinProcSuiv&, OldWinProcPrec&, _
OldWinProcZoom&, OldWinProcImp&, OldWinProcPage&, _
OldWinProcMarge&, OldWinProcSaut&, OldWinProcAide&
Sub ApercuAvantImpression()
Const WH_CBT& = &H5
LeHook = SetWindowsHookEx(WH_CBT, AddressOf HookMsgb, 0&,
GetCurrentThreadId) Application.Dialogs(xlDialogPrintPreview).Show
End Sub
Private Function HookMsgb&(ByVal lMsg&, ByVal wParam&, ByRef lParam&)
Const GWL_WNDPROC& = -4&, HCBT_SETFOCUS& = 9&
Dim hwnd&
If lMsg = HCBT_SETFOCUS Then
hwnd = GetParent(wParam)
UnhookWindowsHookEx LeHook
OldWinProcSuiv = SetWindowLong(GetDlgItem(hwnd, 0&),
GWL_WNDPROC, AddressOf SuivProc) OldWinProcPrec > SetWindowLong(GetDlgItem(hwnd, 1&), GWL_WNDPROC, AddressOf
PrecProc) OldWinProcZoom = SetWindowLong(wParam, GWL_WNDPROC,
AddressOf ZoomProc) OldWinProcImp > SetWindowLong(GetDlgItem(hwnd, 3&), GWL_WNDPROC, AddressOf
ImpProc) OldWinProcPage = SetWindowLong(GetDlgItem(hwnd, 4&),
GWL_WNDPROC, AddressOf PageProc) OldWinProcMarge > SetWindowLong(GetDlgItem(hwnd, 5&), GWL_WNDPROC, AddressOf
MargeProc) OldWinProcSaut = SetWindowLong(GetDlgItem(hwnd, 6&),
GWL_WNDPROC, AddressOf SautProc) OldWinProcAide > SetWindowLong(GetDlgItem(hwnd, 9&), GWL_WNDPROC, AddressOf AideProc)
End If
End Function
Private Function SuivProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcSuiv
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
SuivProc = CallWindowProc(OldWinProcSuiv, hwnd, Msg, wParam,
lParam)
End Function
Private Function PrecProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcPrec
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
PrecProc = CallWindowProc(OldWinProcPrec, hwnd, Msg, wParam,
lParam)
End Function
Private Function ZoomProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcZoom
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
ZoomProc = CallWindowProc(OldWinProcZoom, hwnd, Msg, wParam,
lParam)
End Function
Private Function ImpProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcImp
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
ImpProc = CallWindowProc(OldWinProcImp, hwnd, Msg, wParam, lParam)
End Function
Private Function PageProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcPage
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
PageProc = CallWindowProc(OldWinProcPage, hwnd, Msg, wParam,
lParam)
End Function
Private Function MargeProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcMarge
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
MargeProc = CallWindowProc(OldWinProcMarge, hwnd, Msg, wParam,
lParam)
End Function
Private Function SautProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcSaut
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
SautProc = CallWindowProc(OldWinProcSaut, hwnd, Msg, wParam,
lParam)
End Function
Private Function AideProc&(ByVal hwnd&, ByVal Msg&, ByVal wParam&,
ByVal lParam&) Const WM_DESTROY& = &H2, GWL_WNDPROC& = -4&,
BM_SETSTATE& = &HF3 If Msg = WM_DESTROY Then
SetWindowLong hwnd, GWL_WNDPROC, OldWinProcAide
End If
If Msg = BM_SETSTATE Then
If wParam = 1& Then
MsgBox "C'est le bouton " & TitreDeFenetre(hwnd),
vbInformation, "Spécial Lyssandre" Exit Function
End If
End If
AideProc = CallWindowProc(OldWinProcAide, hwnd, Msg, wParam,
lParam)
End Function
Private Function TitreDeFenetre$(hwnd&)
TitreDeFenetre = Space$(50&)
TitreDeFenetre = Left$(TitreDeFenetre, GetWindowText(hwnd,
TitreDeFenetre, 50&))
End Function
'--------Fin de copie
"j-pascal" a écrit dans le message de news:
upy#Bonjour,
Dans la macro suivante, je voudrais une tempo de 2 secondes pendant
la "vue avant impression" et ensuite un msgbox pour valider
l'impression. Ce qui suit ne fonctionne pas ! Si je fais une macro
en enregistrement automatique, je ne vois pas de trace de "fermer"
après "vue avant impression", je pense que le pb est là (?) :
Range("C6:E11").Select
ActiveSheet.PageSetup.PrintArea = "$C$6:$E$11"
ActiveWindow.SelectedSheets.PrintPreview
Application.Wait Now + TimeValue("00:00:02")
[là je pense qu'il manque qqch !]
reponse = MsgBox("Voulez-vous imprimer ?", vbYesNo + vbQuestion +
vbDefaultButton2, "print")
If reponse = 6 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Else: MsgBox ("Bye !")
Merci d'avance pour votre aide,
JP