Option Explicit Public Sub SelectionFitToPapersize() Dim wks As Worksheet Dim intPaperSize%, sngHoehe!, sngBreite! Dim bytAusrichtung As Byte Dim bytMModerZoll As Byte Dim sngZHoehe!, sngSBreite! Dim intZA%, intSA% Dim sngRaenderRL!, sngRaenderOU!, sngKopfFuss! Set wks = ThisWorkbook.ActiveSheet intZA = Selection.Rows.Count intSA = Selection.Columns.Count bytAusrichtung = wks.PageSetup.Orientation intPaperSize = wks.PageSetup.PaperSize 'Zoll oder mm Select Case intPaperSize Case 8 To 13, 27 To 36 bytMModerZoll = 1 Case 32767, 205, 256 MsgBox "Benutzerdefinierte Blattgrößen werden nicht unterstützt, sorry!" Exit Sub Case Else MsgBox "Ihre Blattgröße (Zoll) ist noch nicht im Code berücksichtigt" _ & Chr(13) & "Bitte passen Sie den Code an oder wählen Sie ein anderes Papierformat." Exit Sub End Select 'wenn mm If bytMModerZoll Then sngRaenderRL = (wks.PageSetup.LeftMargin * 0.0357) + (wks.PageSetup.RightMargin * 0.0357) sngRaenderOU = (wks.PageSetup.TopMargin * 0.0357) + (wks.PageSetup.BottomMargin * 0.0357) sngKopfFuss = (wks.PageSetup.HeaderMargin * 0.0357) + (wks.PageSetup.FooterMargin * 0.0357) 'Hochformat If bytAusrichtung = 1 Then Select Case intPaperSize Case Is = 8 sngBreite = 29.7 - sngRaenderRL sngHoehe = 42# - sngRaenderOU - sngKopfFuss Case Is = 9 sngBreite = 21# - sngRaenderRL sngHoehe = 29.7 - sngRaenderOU - sngKopfFuss Case Else MsgBox "Ihre Blattgröße ist noch nicht im Code berücksichtigt" _ & Chr(13) & "Bitte passen Sie den Code an oder wählen Sie ein anderes Papierformat." Exit Sub End Select Else 'Querformat Select Case intPaperSize Case Is = 8 sngBreite = 42# - sngRaenderRL sngHoehe = 29.7 - sngRaenderOU - sngKopfFuss Case Is = 9 sngBreite = 29.7 - sngRaenderRL sngHoehe = 21# - sngRaenderOU - sngKopfFuss Case Else MsgBox "Ihre Blattgröße ist noch nicht im Code berücksichtigt" _ & Chr(13) & "Bitte passen Sie den Code an oder wählen Sie ein anderes Papierformat." Exit Sub End Select End If Else Exit Sub End If sngZHoehe = (sngHoehe / intZA) sngSBreite = (sngBreite / intSA) 'bedingt durch die Stufen bei Zeilenhoehe(0.25) und Spaltenbreite(0.1) sind hier Anpassungen erforderlich 'die hier verwendeten Zahlen (28 und 4.9) sind durch Testen entstanden 'und sind von Blattformat, Zeilen- u. Spaltenanzahl abhängig 'Ich bitte an dieser Stelle um Erklärung, ob und wenn ja wie man das lösen kann 'außerdem sind Zeilenhöhe auf 409.5 und Spaltenbreite auf 255 limitiert If Round((sngZHoehe * 28 * 100) / 25) * 0.25 > 409.5 Then Selection.RowHeight = 409.5 _ Else Selection.RowHeight = Round((sngZHoehe * 28 * 100) / 25) * 0.25 If Round(sngSBreite * (4.9), 1) > 255 Then Selection.ColumnWidth = Round(sngSBreite * (4.9), 1) = 255 _ Else Selection.ColumnWidth = Round(sngSBreite * (4.9), 1) With wks.PageSetup .PrintArea = Selection.Address .CenterHorizontally = True .CenterVertically = True End With ActiveWindow.SelectedSheets.PrintPreview End Sub Sub Ruecksetzen() ActiveSheet.Cells.RowHeight = 12.75 ActiveSheet.Cells.ColumnWidth = 10.71 ActiveSheet.PageSetup.PrintArea = "" End Sub 'xlPaper10x14 16 US-10 x 14 Zoll 'xlPaper11x17 17 US-11 x 17 Zoll 'xlPaperA3 8 A3 (297 mm x 420 mm) 'xlPaperA4 9 A4 (210 mm x 297 mm) 'xlPaperA4Small 10 A4 Small (210 mm x 297 mm) 'xlPaperA5 11 A5 (148 mm x 210 mm) 'xlPaperB4 12 B4 (250 mm x 354 mm) 'xlPaperB5 13 A5 (148 mm x 210 mm) 'xlPaperCsheet 24 US Paper Size C 'xlPaperDsheet 25 US Paper Size D 'xlPaperEnvelope10 20 US-Envelope #10 (4 1/8 x 9 1/2 Zoll) 'xlPaperEnvelope11 21 Envelope #11 (4-1/2 x 10-3/8 Zoll) 'xlPaperEnvelope12 22 US-Envelope #12 (4 1/2 x 11 Zoll) 'xlPaperEnvelope14 23 Envelope #14 (5 x 11-1/2 Zoll) 'xlPaperEnvelope9 19 US-Envelope #9 (3 1/8 x 8 1/2 Zoll) 'xlPaperEnvelopeB4 33 US-Envelope B4 (250 mm x 353 mm) 'xlPaperEnvelopeB5 34 US-Envelope B5 (176 mm x 250 mm) 'xlPaperEnvelopeB6 35 US-Envelope B6 (176 mm x 125 mm) 'xlPaperEnvelopeC3 29 US-Envelope C3 (324 mm x 458 mm) 'xlPaperEnvelopeC4 30 US-Envelope C4 (229 mm x 324 mm) 'xlPaperEnvelopeC5 28 US-Envelope C5 (162 mm x 229 mm) 'xlPaperEnvelopeC6 31 US-Envelope C6 (114 mm x 162 mm) 'xlPaperEnvelopeC65 32 US-Envelope C65 (114 mm x 229 mm) 'xlPaperEnvelopeDL 27 US-Envelope DL (110 mm x 220 mm) 'xlPaperEnvelopeItaly 36 US-Envelope (110 mm x 230 mm) 'xlPaperEnvelopeMonarch 37 US-Envelope Monarch (3-7/8 x 7-1/2 Zoll) 'xlPaperEnvelopePersonal 38 US-Envelope (3 5/8 x 6 1/2 Zoll) 'xlPaperEsheet 26 US Paper Size E 'xlPaperExecutive 7 US-Executive (7 1/2 x 10 1/2 Zoll) 'xlPaperFanfoldLegalGerman 41 Deutsch-Legal-Endlos (8 1/2 x 13 Zoll) 'xlPaperFanfoldStdGerman 40 Deutsch-Legal-Endlos (8 1/2 x 13 Zoll) 'xlPaperFanfoldUS 39 US-Standard-Endlos (14 7/8 x 11 Zoll) 'xlPaperFolio 14 US-Folio (8-1/2 x 13 Zoll) 'xlPaperLedger 4 Ledger 17 x 11 in (17 x 11 Zoll) 'xlPaperLegal 5 Legal (8-1/2 x 14 Zoll) 'xlPaperLetter 1 US-Letter (8-1/2 x 11 Zoll) 'xlPaperLetterSmall 2 US-Letter Small (8-1/2 x 11 Zoll) 'xlPaperNote 18 US-Note 81/2 x 11 in (21,59 x 27,94 cm) 'xlPaperQuarto 15 Quarto (215 mm x 275 mm) 'xlPaperStatement 6 US-Statement (5 1/2 x 8 1/2 Zoll) 'xlPaperTabloid 3 US-Tabloid (11 x 17 Zoll) 'xlPaperUser 256 Benutzerdefiniert '' Orientation: 'xlLandscape 2 Querformatmodus 'xlPortrait 1 Hochformatmodus