【发布时间】:2017-10-12 18:15:54
【问题描述】:
我正在尝试创建一个宏来识别和 PDF 个人银行家的投资组合。宏将过滤银行家的名字(仅显示他们的投资组合),并将 PDF 和银行家的名字放在 PDF 文件中。宏运行没有任何错误。它能够识别银行家,添加到集合中,并过滤所有银行家。但是,它不包含任何内容。我无法确定问题所在。请帮忙!
我的代码:
Sub CreatePDFs()
'
' CreatePDFs Macro
'
' Identify distinct banker names in Column E and store in a collection
Dim BankerCollection As Collection
Dim Banker As Variant
Dim Rng As Range
Dim Cell As Range
Set Rng = Range("E5", Range("E5").End(xlDown))
Set BankerCollection = New Collection
On Error Resume Next
For Each Cell In Rng.Cells
BankerCollection.Add Cell.Value, CStr(Cell.Value)
Next Cell
' Loop through each banker name in the collection
For Each Banker In BankerCollection
' Copy each banker name to cell B1
Range("B1").Value = Banker
Range("B1").Font.Bold = True
' filter on the banker name, and PDF with banker name in document title
Range("E4", Range("E4").End(xlDown)).AutoFilter Field:=1, Criteria1:=Banker, VisibleDropDown:=False
ThisFile = Banker + " Portfolio"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisFile, OpenAfterPublish:=True
Next Banker
End Sub
【问题讨论】:
-
"宏运行没有任何错误。"当您使用
On Error Resume Next语句屏蔽错误时,如何判断它没有错误?注释掉那一行,看看是否有错误发生。 -
您能否评论除 Activesheet.ExportAs 之外的所有其他行并尝试将错误归零。
-
您在创建 PDF 时看到它们打开了吗?创建 PDF 文件后,您可能没有在正确的文件夹中找到它们。
-
不,我没有看到 PDF。我不认为它们是被创造出来的。我签入了默认文件夹,但没有创建任何文件。