Imprimer page de Userform en paysage

Bonjour,

j’ai un userform “Test_multipage” avec plusieurs pages

image

Je voudrais imprimer la page “Statistiques/graphiques” en mode paysage. J’ai donc sur cette même page mis un bouton dans lequel j’ai écris ce code :

ActiveSheet.PageSetup.Orientation = xlLandscape
ActiveSheet.PageSetup.CenterHorizontally = True
ActiveSheet.PageSetup.CenterVertically = True
Test_multipage.PrintForm

Mais ça n’imprime qu’en paysage.

Quelqu’un a til la solution ?

MERCI+++

Correction…ça n’imprime qu’en portrait pardon !

Bonjour,

J’ai adapté ce code depuis la page :

https://www.mrexcel.com/board/threads/print-userform-in-landscape-mode.391147/

Mets le bouton Command1 sur le userform. Attache au bouton le code :

Private Sub CommandButton1_Click()
  DoEvents
  test
End Sub

Dans un module standard, mets :

Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
 
 
Public Const VK_SNAPSHOT = 44
Public Const VK_LMENU = 164
Public Const KEYEVENTF_KEYUP = 2
Public Const KEYEVENTF_EXTENDEDKEY = 1

Sub test()
  keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY, 0
  keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0
  keybd_event VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY + _
                              KEYEVENTF_KEYUP, 0
  keybd_event VK_LMENU, 0, KEYEVENTF_EXTENDEDKEY + _
                           KEYEVENTF_KEYUP, 0
  DoEvents
  Workbooks.Add
  Application.Wait Now + TimeValue("00:00:01")
  ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
                           DisplayAsIcon:=False
  ActiveSheet.Range("A1").Select
  'added to force landscape
  ActiveSheet.PageSetup.Orientation = xlLandscape
  ActiveWindow.SelectedSheets.PrintOut Copies:=1
  ActiveWorkbook.Close False
End Sub

L'impression se fait sur un nouveau classeur.

Daniel

251005.xlsm (20,1 Ko)

Ce sujet a été automatiquement fermé après 30 jours. Aucune réponse n’est permise dorénavant.