Sub Yazdirma_alanlarini_Kaydet()
Dim ws As Worksheet, i As Integer, j As Integer
Dim myrange As Variant, sayfa As Integer, ss As Long
Dim ust As Range, alt As Range, rng As String, unirng As String
Set ws = ActiveSheet
For Each ws In Worksheets
Set ust = ws.Range("$A$1")
ws.Activate
ActiveWindow.View = xlPageBreakPreview
ss = ws.UsedRange.Rows.Count
i = 0
If ws.Name = "Ö" Then
ws.PageSetup.PrintArea = ""
If ws.Range("C5") <> "" Then ws.PageSetup.PrintArea = "A1:D30"
End If
If ws.Name = "Sİ" Then
ws.PageSetup.PrintArea = ""
If ws.Range("A12") <> "" Then ws.PageSetup.PrintArea = "A1:D30"
End If
If ws.Name = "EA" Then
ws.PageSetup.PrintArea = ""
sayfa = ws.PageSetup.Pages.Count
myrange = "B8, B54, B100, B146, B192, B238, B284, B330, B376, B422, B468, B514"
myrange = Split(myrange, ",")
For j = 1 To sayfa
If Not IsEmpty(Range(myrange(i))) Then
If j < sayfa Then
Set alt = Range(ws.HPageBreaks(j).Location.Address).Offset(-1, 4)
Else
Set alt = Range("A" & ss).Offset(0, 4)
rng = (ust.Address & ":" & alt.Address)
unirng = unirng & "," & rng
Exit For
End If
rng = (ust.Address & ":" & alt.Address)
Set ust = alt.Offset(1, -4)
unirng = unirng & "," & rng
Else
Set alt = Range(ws.HPageBreaks(j).Location.Address).Offset(-1, 4)
Set ust = alt.Offset(1, -4)
End If
i = i + 1
Next j
unirng = Mid(unirng, 2, Len(unirng))
ws.PageSetup.PrintArea = unirng
unirng = ""
End If
If ws.Name = "K" Then
ws.PageSetup.PrintArea = ""
sayfa = ws.PageSetup.Pages.Count
myrange = "B8, B48, B88, B128, B168, B208, B248, B288, B328, B368, B408, B448"
myrange = Split(myrange, ",")
For j = 1 To sayfa
If Not IsEmpty(Range(myrange(i))) Then
If j < sayfa Then
Set alt = Range(ws.HPageBreaks(j).Location.Address).Offset(-1, 4)
Else
Set alt = Range("A" & ss).Offset(0, 4)
rng = (ust.Address & ":" & alt.Address)
unirng = unirng & "," & rng
Exit For
End If
rng = (ust.Address & ":" & alt.Address)
Set ust = alt.Offset(1, -4)
unirng = unirng & "," & rng
Else
Set alt = Range(ws.HPageBreaks(j).Location.Address).Offset(-1, 4)
Set ust = alt.Offset(1, -4)
End If
i = i + 1
Next j
unirng = Mid(unirng, 2, Len(unirng))
ws.PageSetup.PrintArea = unirng
unirng = ""
End If
If ws.Name = "DK" Then
ws.PageSetup.PrintArea = ""
sayfa = ws.PageSetup.Pages.Count
myrange = "B8, B56, B104, B152, B200, B248, B296, B344, B392, B440, B488, B536"
myrange = Split(myrange, ",")
For j = 1 To sayfa
If Not IsEmpty(Range(myrange(i))) Then
If j < sayfa Then
Set alt = Range(ws.HPageBreaks(j).Location.Address).Offset(-1, 4)
Else
Set alt = Range("A" & ss).Offset(0, 4)
rng = (ust.Address & ":" & alt.Address)
unirng = unirng & "," & rng
Exit For
End If
rng = (ust.Address & ":" & alt.Address)
Set ust = alt.Offset(1, -4)
unirng = unirng & "," & rng
Else
Set alt = Range(ws.HPageBreaks(j).Location.Address).Offset(-1, 4)
Set ust = alt.Offset(1, -4)
End If
i = i + 1
Next j
unirng = Mid(unirng, 2, Len(unirng))
ws.PageSetup.PrintArea = unirng
unirng = ""
End If
ActiveWindow.View = xlNormalView
Next ws
Sheets(Array("Ö", "Sİ", "EA", "K", "DK")).Select
'Sheets(Array("Ö", "Sİ", "EA", "K", "DK")).PrintOut , preview:=True
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\Kontrol.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Sheets(1).Select
End Sub