Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1736to1740
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Drucken einer UserForm

Drucken einer UserForm
05.02.2020 14:48:25
Andreas
Hallo liebes Forum,
Ich möchte eine UserForm drucken.
Funktioniert auch.
Private Sub CommandButton1_Click()
PrintForm
End Sub
Da die UserForm aber so groß ist fehlt ein Teil des ausdrucks.
Punkt 1: wie müsste es Assehen wenn ich Querformat drucken möchte?
Punkt 2: und wie bekomme ich die UserForm auf eine Seite gedruckt wird.(verkleinert wird)
Mfg Andreas

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Drucken einer UserForm
05.02.2020 16:47:54
Nepumuk
Hallo Andreas,
teste mal:
Option Explicit
Option Private Module

Private Declare Function OpenClipboard Lib "user32.dll" ( _
    ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32.dll" () As Long
Private Declare Function CloseClipboard Lib "user32.dll" () As Long

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 MapVirtualKeyA Lib "user32.dll" ( _
    ByVal wCode As Long, _
    ByVal wMapType As Long) As Long

Private Const KEYEVENTF_KEYUP As Long = &H2

Public Sub PrintUserform()
    
    Dim objWorksheet As Worksheet
    Dim objShape As Shape
    Dim lngColumn As Long, lngRow As Long
    Dim strAddress As String
    Dim lngAltScan As Long
    
    Call OpenClipboard(Application.hwnd)
    Call EmptyClipboard
    Call CloseClipboard
    
    lngAltScan = MapVirtualKeyA(vbKeyMenu, 0)
    Call keybd_event(vbKeyMenu, lngAltScan, 0, 0)
    DoEvents
    Call keybd_event(vbKeySnapshot, 0&, 0&, 0&)
    DoEvents
    Call keybd_event(vbKeyMenu, lngAltScan, KEYEVENTF_KEYUP, 0)
    DoEvents
    
    Set objWorksheet = ThisWorkbook.Worksheets.Add
    
    With objWorksheet
        
        On Error Resume Next
        Do
            Call .Paste
            If Err.Number = 0 Then Exit Do
            Err.Clear
            DoEvents
        Loop
        On Error GoTo 0
        
        Set objShape = .Shapes(1)
        
        For lngColumn = 1 To .Columns.Count
            If .Range(.Cells(1, 1), .Cells(1, lngColumn)).Width > objShape.Width Then Exit For
        Next
        For lngRow = 1 To .Rows.Count
            If .Range(.Cells(1, 1), .Cells(lngRow, 1)).Height > objShape.Height Then Exit For
        Next
        
        strAddress = .Range(.Cells(1, 1), .Cells(lngRow, lngColumn)).Address
        
        With .PageSetup
            
            .PrintArea = strAddress
            .Orientation = xlLandscape
            .LeftMargin = Application.CentimetersToPoints(0.5)
            .RightMargin = Application.CentimetersToPoints(0.5)
            .TopMargin = Application.CentimetersToPoints(0.5)
            .BottomMargin = Application.CentimetersToPoints(0.5)
            .CenterVertically = True
            .CenterHorizontally = True
            .Zoom = False
            .FitToPagesTall = 1
            .FitToPagesWide = 1
            
        End With
        
        Call .PrintOut
        
        Application.DisplayAlerts = False
        Call .Delete
        Application.DisplayAlerts = True
        
    End With
    
    Set objShape = Nothing
    Set objWorksheet = Nothing
End Sub

Der Aufruf aus dem Userform:
Private Sub CommandButton1_Click()
    Call PrintUserform
End Sub

Gruß
Nepumuk
Anzeige
AW: Drucken einer UserForm
05.02.2020 20:42:02
Crefoman
Userbild
Ich hoffe du Siehst das Foto.
Das Skript funktioniert leider nicht.
Wenn du der Nepumuk von der Seite Office-Lösungen bist, schau die das bitte an.
http://www.office-loesung.de/p/viewtopic.php?f=166&t=828681&start=15
Das ist die Selbe Mappe
Ich glaube ich habe mir da etwas zu viel aufgehalst, da ich zwar gerne mit Excel arbeite, aber meine Kenntisse reichen leider nicht ganz dafür, aber man lernt ja immer wieder dazu.
Wäre Dir dankbar für deine unterstützung, das Objekt befindet sich auf der Zielgerade,
Danke im vorraus.
Mfg Andreas
Anzeige
AW: Drucken einer UserForm
06.02.2020 08:00:57
Nepumuk
Hallo Andreas,
ändere die Funktionen so:
Private Declare PtrSafe Function OpenClipboard Lib "user32.dll" ( _
    ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function EmptyClipboard Lib "user32.dll" () As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32.dll" () As Long


Private Declare PtrSafe Sub keybd_event Lib "user32.dll" ( _
    ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, _
    ByVal dwExtraInfo As LongPtr)
Private Declare PtrSafe Function MapVirtualKeyA Lib "user32.dll" ( _
    ByVal wCode As Long, _
    ByVal wMapType As Long) As Long

Gruß
Nepumuk
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige