Variabel PDF Zusammenführen
17.03.2022 11:07:59
Lönne75
ich würde gerne mehrere PDF zusammenführen und hierbei flexibel bleiben.
Für zwei PDF (Spalte A, Spalte B) nutze ich bis dato. untenstehenden VBA.
Meine Frage wäre, welchen Befehl bzw. Zeile muss ich anpassen, dass man für drei PDF (+Spalte C), vier PDF (+Spalte D) usw. diese VBA weiterhin verwenden kann.
Vielen Dank vorab und schöne Grüße
Option Explicit
Sub multidoc()
Dim fso As Object, WshShell As Object
Dim strOrdner As String, i As Long
Dim strMulti As String, strCommand As String, strGS As String
Set fso = CreateObject("Scripting.FileSystemObject")
'Pfad zu gswin32c.exe anpassen
strGS = "C:\Programme\Textbearbeitung\Ghostscript\gs8.53\bin\gswin32c.exe"
'Ausgabeordner anpassen
strOrdner = "E:\Temp\Simon test"
With Tabelle1 'anpassen
'Spalte A : Dateinamen mit komplettem Pfad
'Spalte B : Dateinamen mit komplettem Pfad
For i = 2 To .UsedRange.Rows.Count
If fso.FileExists(.Cells(i, 1).Value) And fso.FileExists(.Cells(i, 2).Value) Then
strMulti = " " & Chr(34) & .Cells(i, 1).Value & Chr(34) & " " & Chr(34) & .Cells(i, 2).Value & Chr(34)
strOrdner = fso.getfolder(strOrdner).ShortPath
strGS = fso.GetFile(strGS).ShortPath
strCommand = strGS & " -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=" & Chr(34)
strCommand = strCommand & strOrdner & "\"
'Name der Ausgabedatei = Name der Datei in der Spalte A
strCommand = strCommand & fso.GetFile(.Cells(i, 1).Value).Name & Chr(34) & strMulti
Debug.Print strCommand
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strCommand, 0, True
Set WshShell = Nothing
End If
Next
End With
Set fso = Nothing
MsgBox "Fertig"
End
Sub