如何将多个范围导出到单个PDF?
我想从同一张纸上输出多个范围到一个pdf。
帐户1在列A中开始,帐户2在列C中开始,帐户3在列E中开始,依此类推。 每个帐户可以是n行,但是我只希望在pdf中的每个帐户上最多有50行,例如
Account 1 = 100 rows long Account 2 = 32 rows long Account 3 = 56 rows long
在这种情况下,我希望我的pdf看起来像这样:
Sheet 1 = first 50 rows of account 1 Sheet 2 = next 50 rows of account 1 Sheet 3 = first 32 rows of account 2 Sheet 4 = first 50 rows of account 3 Sheet 5 = next 6 rows of account 3
任何人都可以想到一个简单的方法来做到这一点,不涉及到复制范围到一个新的工作表?
你将不得不作出代码来select适当的范围,但这将工作:
Dim myfilename As String Dim mysheet As Worksheet Dim printRange As Range myfilename = "C:\MyFolder\MyFile.pdf" Set mysheet = ActiveWorkbook.Sheets("Sheet2") 'This is needed because even when you clear page breaks, it automatically creates a horizontal one around row 50 Set mysheet.HPageBreaks.Item(1).Location = mysheet.Range("A51") 'Make 2 vertical page breaks mysheet.VPageBreaks.Add Before:=Range("C1") mysheet.VPageBreaks.Add Before:=Range("E1") 'Insert code to set range here Set printRange = mysheet.range("A1:F50,A51:B100,E51:F100") printRange.ExportAsFixedFormat Type:=xlTypePDF _ , Filename:=myfilename
请注意,为了正常工作,需要正确设置分页符。 通过设置分页符在你想要的地方,这将打印select页面。