2016-01-20 67 views
-1

我正在嘗試編寫一個宏以在下拉菜單中循環。每當下拉列表中的值發生變化時,它將更改工作表上的值。我不會爲VBA數組中的下拉列表中的每個值捕獲一系列工作表,然後將所有這些範圍導出到單個PDF。我可以一次將它們導出爲多個PDF,但這不是目標。我似乎遇到的問題是將不同的範圍存儲在數組中。使用VBA將多個範圍導出到單個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 

謝謝!

+0

你總是可以複製你想要的數據粘貼到爲相應格式的新的工作表PDF導出,導出爲PDF,然後刪除表單。 – CustodianOfCode

+0

謝謝CustodianOfCode ...這就是我最終做的! – GarAust89

回答

0

所以你不能將它們收集齊全到一個單一的陣列,解決方案是創建多個虛擬表和刪除它們完成時: