vbscript 将活动表导出为PDF

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 将活动表导出为PDF相关的知识,希望对你有一定的参考价值。

Sub PDFActiveSheet()

    Dim wsA As Worksheet
    Dim wbA As Workbook
    Dim strTime As String
    Dim strName As String
    Dim strPath As String
    Dim strFile As String
    Dim strPathFile As String
    Dim myFile As Variant
    On Error GoTo errHandler
    
    Set wbA = ActiveWorkbook
    Set wsA = ActiveSheet
    strTime = Format(Now(), "yyyymmdd\_hhmm")
    
        'get active workbook folder, if saved
        strPath = wbA.path
        If strPath = "" Then
          strPath = Application.DefaultFilePath
        End If
        strPath = strPath & "\"
        
        'replace spaces and periods in sheet name
        strName = Replace(wsA.Name, " ", "")
        strName = Replace(strName, ".", "_")
        
        'create default name for savng file
        strFile = strName & "_" & strTime & ".pdf"
        strPathFile = strPath & strFile
        
        'use can enter name and
        ' select folder for file
        myFile = Application.GetSaveAsFilename _
            (InitialFileName:=strPathFile, _
                FileFilter:="PDF Files (*.pdf), *.pdf", _
                Title:="Select Folder and FileName to save")
        
        'export to PDF if a folder was selected
        If myFile <> "False" Then
            wsA.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                fileName:=myFile, _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
            'confirmation message with file info
            MsgBox "PDF file has been created: " _
              & vbCrLf _
              & myFile
        End If
        
exitHandler:
            Exit Sub
errHandler:
            MsgBox "Could not create PDF file"
            Resume exitHandler
End Sub

以上是关于vbscript 将活动表导出为PDF的主要内容,如果未能解决你的问题,请参考以下文章

vbscript 将整个工作簿导出为PDF

vbscript 使用文件对话框将工作簿导出为PDF

VBSCRIPT 保存

vbscript将word doc转换为pdf

C# 计划任务系列

Java将HTML导出为PDF