Temat: drukowanie zakładek do pdf'a poprzez VBA
'skleiłam' i kod działa! :)
mam jedno istotne pytanie:
żeby obszar drukowania w istocie był taki potrzebuje musze na poczatku zaznaczyc wszystkie zakladki w ustawieniach "Fit All Columns On One Page"
Zastanawiam sie czy taki sposób: tj. nagranie tego fragmentu makra bedzie ok? Zaznaczam pogrubieniem w makrze to co za to odpowiada Nie wiem czy jest to dość uniwersalne?
ponizej kod:
Sub printing_draft()
Dim n As Integer
Dim lw As Integer
Dim m As String
Dim shArkusz As Worksheet
ChDir ThisWorkbook.Path
Sheets("TASKS").Select
n = 6
Do While Sheets("TASKS").Range("$G" & n) <> ""
'zapisujemy zmienna z zakladki TASKS jako m
ActiveSheet.Range("$G" & n).Select
m = Sheets("TASKS").Range("$G" & n)
'odwolujemy sie do niej jako do nazyw kolejnej zakladki
Sheets(m).Select
'liczymy ilosc wierszy w akrywnej zakaldce
lw = ActiveSheet.UsedRange.Rows.Count
Range("A1:G" & lw).Select
Application.CutCopyMode = False
'obbszar 'do druku' jes t zalezny od ilosci aktywnych wierszy
ActiveSheet.PageSetup.PrintArea = "$A$1:$G$" & lw
'wiersz 45 jest na sztywno gdyz tak chcemy odroznic 1 strone faktury
Rows("45:45").Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
Range("B41").Select
'zwiekszamy licznik petli
n = n + 1
Loop
MsgBox "Drukuj wszystkie arkusze biezcego skoroszytu do pdf'a", vbInformation, "Procedura drukowania uruchamia sie skrotem Ctrl+Shift+P"
'
'ustawiamy dla wszystkich zakladek, zeby drukowanie bylo "Fit columns on one page"
For Each shArkusz In Worksheets
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 0
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Next shArkusz '
'teraz przechodzimy do drukowania do pdf'u kazdej z zakladki z listy w zakladce "TASKS"
Sheets("TASKS").Select
n = 6
Do While Sheets("TASKS").Range("$G" & n) <> ""
m = Sheets("TASKS").Range("$G" & n)
Sheets(m).ExportAsFixedFormat Type:=xlTypePDF, Filename:=m & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
n = n + 1
Loop
MsgBox "Koniec drukowania", vbInformation, "Procedura drukowania uruchamia sie skrotem Ctrl+Shift+P"
End Sub
Ten post został edytowany przez Autora dnia 07.04.16 o godzinie 14:15