如果Adobe当前打开一个版本,VBA查看表单失败

我写了下面的函数来查看一个PDF格式的电子表格,点击一个选项button。

Public Function RunPDFReport(CellRange As String) As String Application.ScreenUpdating = False refPositionDetails.Range("O2").Value = dsbDashboard.Range(CellRange).Value dsbDashboard.Unprotect On Error GoTo ErrHandler: With refPositionDetails .Visible = xlSheetVisible .ExportAsFixedFormat Type:=xlTypePDF, Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True, from:=1, To:=3 .Visible = xlSheetVeryHidden Application.ScreenUpdating = True dsbDashboard.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True dsbDashboard.Activate End ErrHandler: MsgBox "Report Canceled", vbCritical End With End Function 

这工作正常,它everyithng应该做的。 除了如果我有当前打开的PDF的早期副本,该过程直接到我的error handling程序。 它应该能够仍然打开新的PDF并覆盖旧的或打开一个新的副本。

我错过了什么?

你不能,如果它目前打开…但我没有看到你的代码中的文件名位置。 为了使这个工作,你需要循环的名称,一旦成功达到你退出函数的名称…所以也许这将有助于?

 name = [whatever you want the names tobe pulled from] Number_of_Pdfs_you_should_close = 0 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\tpike\Documents\" & name & ".pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ True Number_of_PDFs_you_should_close = Number_of_PDFs_you_should_close + 1 name = name + "(" & Number_of_Pdfs_you_should_close & ")"