mfg Wolfgang
Option Explicit
Private Declare Sub keybd_event Lib "user32.dll" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" _
Alias "MapVirtualKeyA" (ByVal wCode As Long, _
ByVal wMapType As Long) As Long
Const VK_MENU = &H12 'ALT
Private Sub CommandButton1_Click()
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0 ' 0 = ALT drücken
keybd_event vbKeySnapshot, 0, 0, 0
DoEvents
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 2, 0 ' 2 = ALT loslassen
Application.OnTime Now + TimeSerial(0, 0, 1), "Main"
Unload Me
End Sub
Code in einem Modul:Option Explicit
Sub Main()
ThisWorkbook.Worksheets.Add
With ActiveSheet
.Paste
' .PrintOut
' Application.DisplayAlerts = False
' .Delete
' Application.DisplayAlerts = True
End With
End Sub
Du must natürlich noch bei den entsprechenden Zeilen das Kommentarzeichen entfernen. Wenn die UserForm mehr "Breit" als "Hoch" ist, kannst Du natürlich auch vor dem Druck auf Querformat umstellen. Das alles per Code prüfen und einstellen - nicht von Hand. :-)