使用VBA将多个范围导出为单个PDF

时间:2016-01-20 19:44:08

标签: excel vba excel-vba pdf

我试图编写一个宏来循环显示下拉菜单。每次下拉列表中的值更改时,它都会更改工作表上的值。我不想为VBA数组的下拉列表中的每个值捕获一系列工作表,然后将所有这些范围导出为单个PDF。我能够一次一个地导出它们到多个PDF,但这不是目标。我似乎遇到的问题是在数组中存储不同的范围。

我的代码如下:

Sub bill_exporter()
' Macro to export billing estimates to a single pdf

'Define Filenames and ranges
Dim myfile As String
Dim billsheet As Worksheet
Dim print_area As Excel.Range
Dim site As Range
Dim arr() As Variant
Dim i As Integer


i = 0
myfile = Range("filename").Value
Set billsheet = ActiveWorkbook.Sheets("Mock Bill")

For Each site In Range("meters")

    billsheet.Calculate
    billsheet.Range("$R$10").Value = site

    'Create Vertical Page Breaks
    billsheet.VPageBreaks.Add Before:=Range("C3")
    billsheet.VPageBreaks.Add Before:=Range("R3")

    'Set Print Area
    Set print_area = billsheet.Range("C3:R50")

    Set arr(i) = print_area.Value

    i = i + 1

Next site

Array(arr).ExportAsFixedFormat Type:=xlTypePDF, Filename:=myfile

End Sub

在预先感谢您的任何帮助!

1 个答案:

答案 0 :(得分:0)

所以你不能将它们全部收集到一个数组中,解决方案是创建多个虚拟表并在完成后删除它们:

相关问题