Advertisement
YasserKhalil2019

T4093_Export To One PDF All Names Blocks

Oct 12th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. https://excel-egy.com/forum/t4093
  2. ---------------------------------
  3.  
  4. Sub Export_To_One_PDF_All_Names_Block()
  5. Dim wb As Workbook, ws As Worksheet, sh As Worksheet, lr As Long, m As Long, r As Long
  6.  
  7. Application.ScreenUpdating = False
  8. Set wb = Workbooks.Add(xlWBATWorksheet)
  9. Set ws = ThisWorkbook.Worksheets("Sheet1")
  10. Set sh = ThisWorkbook.Worksheets("Template")
  11. lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
  12. m = 2: r = 1
  13.  
  14. Do Until m >= lr
  15. sh.Copy After:=wb.Worksheets(wb.Worksheets.Count)
  16.  
  17. With ActiveSheet
  18. .Range("D13").Resize(16, 2).Value = ws.Range("A" & m).Resize(16, 2).Value
  19.  
  20. Application.PrintCommunication = False
  21. With .PageSetup
  22. .PrintArea = "$A$1:$G$38"
  23. .RightHeader = "&""Arial,Bold""&12 " & r
  24. .Orientation = xlPortrait
  25. .FitToPagesWide = 1
  26. .FitToPagesTall = False
  27. End With
  28. Application.PrintCommunication = True
  29. End With
  30. m = m + 16: r = r + 1
  31. Loop
  32.  
  33. Application.DisplayAlerts = False
  34. wb.Worksheets(1).Delete
  35. Application.DisplayAlerts = True
  36.  
  37. wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Environ("USERPROFILE") & "\Desktop\" & "Final Output" & ".pdf"
  38. wb.Close SaveChanges:=False
  39. Application.ScreenUpdating = True
  40.  
  41. MsgBox "The PDF File Equals To ( " & r - 1 & " ) Pages", vbInformation
  42. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement