【发布时间】:2016-10-05 08:51:41
【问题描述】:
我有命名范围的列表,我将每个范围设置为适合单页。我使用以下代码导出为 PDF,并在其中合并为单个页面。
Dim wbBook As Workbook
Dim i As Integer
Dim rs As Range
Set wbBook = ActiveWorkbook
Set rs = wbBook.Names(1).RefersToRange
For i = 2 To wbBook.Names.Count
Set rs = Union(rs, wbBook.Names(i).RefersToRange)
Next
rs.ExportAsFixedFormat xlTypePDF, strPath, , , False
但是当我手动输入范围名称时,下面的代码对我有用。而我的命名范围是动态的。我认为,上面的代码需要一些修改才能工作。有人能帮我完成这项工作吗?
Set rs = wbBook.Range("Page_1,Page_2,Page_3")
rs.Select
Selection.ExportAsFixedFormat xlTypePDF, strPath, , , False
建议的解决方案仍然给出一页。我在页面设置下方提供了,页面设置有问题吗?
With Sheet1.PageSetup
.PrintArea = Range(Cells(iBeginRow, 1), Cells(iRow + 2, 5)).Address
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintQuality = 600
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
然后我动态命名范围
Sheet1.Range(Cells(iBeginRow, 1), Cells(iRow + 2, 5)).Select
Selection.Name = "Page_" & PageNum
【问题讨论】:
-
你遇到了什么错误,在哪一行?
-
对不起,我的问题不清楚。这不是一个错误。我想在导出时保持每个命名范围的页面设置完整;因此每个命名范围数据反映在每个页面中。当我手动输入命名范围时,我能够做到这一点。我想将每个命名范围的原始页面设置保留在“rs”中并在第一组代码中导出。
-
您是否在不同工作表中使用连续范围?
-
我正在处理同一张表中的连续范围。
标签: excel vba dynamic range named