首页 > 解决方案 > 如何将 Access 报表(包括子报表)保存为 Excel 兼容文件和可读 PDF?

问题描述

我定义了一个 Access (Office 365) 报告。当我在我设计的 Access 应用程序中打开它时,它会正确打开并显示正常。该应用程序与处理医疗保健数据有关,因此我们希望通过将报告另存为 PDF(第一个偏好)或 Excel 文件(第二个偏好)来保存报告中的信息日志。代码创建文件,但两个文件中都没有可用的内容。当我尝试打开 excel 文件时,我收到错误“无法打开文件,因为文件格式扩展名无效。”。当我打开 PDF 文件时,它包含错误信息。


我在表单上有一个按钮。这是事件过程。

Private Sub cmdRpt_Excel_Proc_Summary_Click()
        Call ExportReport("Rpt_FileProcessing_Summary", "Rpt_FileProc_Summary", acFormatXLS)
        Call ExportReport("Rpt_FileProcessing_Summary", "Rpt_FileProc_Summary", acFormatPDF)
End Sub

这是 ExportReport 的代码

Sub ExportReport(strQry As String, strOutFile As String, strOutType As String)
    On Error GoTo errHandler

    Dim xlApp As Object, wkbk As Object
    Dim strMsg
    Dim strFileNm As String

    strFileNm = DEFAULT_FOLDER & strOutFile & "_" & Format(Now(), "yyyy-mm-dd_hhnn")

    If strOutType = acFormatXLS Then
        strFileNm = strFileNm & ".xlsx"
    Else
        strFileNm = strFileNm & ".pdf"
    End If

    'DoCmd.OutputTo acOutputReport, strQry, strOutType, strFileNm, , , , acExportQualityScreen
    DoCmd.OutputTo acOutputReport, strQry, strOutType, strFileNm, True

    If strOutType = acFormatXLS Then
        Set xlApp = CreateObject("Excel.Application")
        With xlApp
            .Visible = True
            Set wkbk = .Workbooks.Open(strFileNm)
        End With
    End If
procDone:
    Set wkbk = Nothing
    Set xlApp = Nothing
Exit Sub

errHandler:
    strMsg = Err.Description
    MsgBox strMsg, vbExclamation, "Unanticipated Error"
    Resume procDone

End Sub

错误事件永远不会触发。创建了 excel 和 pdf 文件,但是我无法打开 excel 文件,并且 pdf 文件的内容是:

PDF 文件的内容

任何诊断问题的帮助将不胜感激。提前谢谢

标签: excelms-accesspdfexport

解决方案


尝试使用其他程序来读取这些文件,因为 MS Edge 有时有点奇怪。您可以使用 FireFox 阅读 .pdf

你能打开Excel文件吗?


推荐阅读