【问题标题】:convert all excel files to pdf in their own subfolder vba在自己的子文件夹 vba 中将所有 excel 文件转换为 pdf
【发布时间】:2019-10-06 18:22:46
【问题描述】:

我想将所有 excel 文件转换为 pdf 作为子文件夹中的整个工作簿到其原始子文件夹

我有一个解决方案,但我的电脑有限。所以不支持 PowerShell How can I convert .XLS & .XLXS files to .PDF format and return them to each original subfolder in Powershell?

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    这就是我的做法。

    http://www.rondebruin.nl/copy5_3.htm
    
    
    Sub Convert_Excel_To_PDF()
        Dim MyPath As String, FilesInPath As String
        Dim MyFiles() As String, Fnum As Long
        Dim mybook As Workbook
        Dim CalcMode As Long
        Dim sh As Worksheet
        Dim ErrorYes As Boolean
        Dim LPosition As Integer
    
        'Fill in the path\folder where the Excel files are
        MyPath = "c:\your_path_here\"
    
        FilesInPath = Dir(MyPath & "*.xl*")
        If FilesInPath = "" Then
            MsgBox "No files found"
            Exit Sub
        End If
    
        Fnum = 0
        Do While FilesInPath <> ""
            Fnum = Fnum + 1
            ReDim Preserve MyFiles(1 To Fnum)
            MyFiles(Fnum) = FilesInPath
            FilesInPath = Dir()
        Loop
    
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        If Fnum > 0 Then
            For Fnum = LBound(MyFiles) To UBound(MyFiles)
                Set mybook = Nothing
                On Error Resume Next
                Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
                On Error GoTo 0
    
                If Not mybook Is Nothing Then
    
    
                        LPosition = InStr(1, mybook.Name, ".") - 1
                        mybookname = Left(mybook.Name, LPosition)
                        mybook.Activate
                        'All PDF Files get saved in the directory below:
                        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                            "C:\Documents and Settings\shuerya\Desktop\PDFFiles\" & mybookname & ".pdf", _
                            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                            :=False, OpenAfterPublish:=False
    
                End If
    
                mybook.Close SaveChanges:=False
    
            Next Fnum
        End If
    
        If ErrorYes = True Then
            MsgBox "There are problems in one or more files, possible problem:" _
                 & vbNewLine & "protected workbook/sheet or a sheet/range that not exist"
        End If
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
            .Calculation = CalcMode
        End With
    End Sub
    

    【讨论】:

    • 这并不能解决问题。它甚至没有在子文件夹中看到任何文件。我还想将 excel 文件转换为 pdf 作为其源子文件夹。所以这个宏不可用
    猜你喜欢
    • 2019-04-14
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    相关资源
    最近更新 更多