Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Anzeige
Inhaltsverzeichnis

edited VBA-Script speichert bestimmtes Tabellenblatt als pdf

Forumthread: edited VBA-Script speichert bestimmtes Tabellenblatt als pdf

edited VBA-Script speichert bestimmtes Tabellenblatt als pdf
10.02.2026 08:40:12
Richy89
Guten Morgen!

kann mir Jemand mit Kenntnissen von VBA bei folgender Lösung bitte weiterhelfen:

Untenstehendes script speichert alle Tabellenblätter der xlsx-Dateien als pdf ab.



Sub BatchOpenMultiplePSTFiles()
Dim objShell As Object
Dim objWindowsFolder As Object
Dim strWindowsFolder As String

'Select the specific Windows folder
Set objShell = CreateObject("Shell.Application")
Set objWindowsFolder = objShell.BrowseForFolder(0, "Select a Windows folder:", 0, "")

If Not objWindowsFolder Is Nothing Then
strWindowsFolder = objWindowsFolder.self.Path & "\"

Call ProcessFolders(strWindowsFolder)

'Open the windows folder
Shell "Explorer.exe" & " " & strWindowsFolder, vbNormalFocus
End If
End Sub

Sub ProcessFolders(strPath As String)
Dim objFileSystem As Object
Dim objFolder As Object
Dim objFile As Object
Dim objExcelFile As Object
Dim objWorkbook As Excel.Workbook
Dim strWorkbookName As String

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSystem.GetFolder(strPath)

For Each objFile In objFolder.Files
strFileExtension = objFileSystem.GetExtensionName(objFile)
If LCase(strFileExtension) = "xls" Or LCase(strFileExtension) = "xlsx" Then
Set objExcelFile = objFile
Set objWorkbook = Application.Workbooks.Open(objExcelFile.Path)

strWorkbookName = Left(objWorkbook.Name, (Len(objWorkbook.Name) - Len(strFileExtension)) -1)
objWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath & strWorkbookName & ".pdf"

objWorkbook.Close False
End If
Next

'Process all folders and subfolders
If objFolder.SubFolders.Count > 0 Then
For Each objSubFolder In objFolder.SubFolders
If ((objSubFolder.Attributes And 2) = 0) And ((objSubFolder.Attributes And 4) = 0) Then
ProcessFolders (objSubFolder.Path)
End If
Next
End If
End Sub


Quelle des scripts:
https://www.datanumen.com/de/Blogs/2-effective-methods-to-batch-convert-multiple-excel-workbooks-to-pdf-Dateien/


Dieses script soll so angepasst werden, dass es nur das erste Tabellenblatt "Eingabeformular" jeweils pro xlsx-Datei als pdf abgespeichert wird.
Wie kann man das script entsprechend anpassen?

Anzeige

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: edited VBA-Script speichert bestimmtes Tabellenblatt als pdf
10.02.2026 08:43:44
Richy89
verwendete Excel-Version hatte ich angegeben ist eigentlich 2021: "MS Office LTSC Professional Plus 2021"
AW: edited VBA-Script speichert bestimmtes Tabellenblatt als pdf
10.02.2026 09:37:23
RPP63
Moin!
Es gibt auch eine Worksheet.ExportAsFixedFormat-Methode.
Ungetestet:
Statt
objWorkbook.ExportAsFixedFormat
nimmst Du
objWorkbook.Worksheets(1).ExportAsFixedFormat

Gruß Ralf
Anzeige
AW: edited VBA-Script speichert bestimmtes Tabellenblatt als pdf
10.02.2026 10:01:30
Richy89
Vielen herzlichen Dank Ralf!

Das hat wunderbar geklappt :)

LG Richy

Forumthreads zu verwandten Themen

Anzeige
Anzeige
Anzeige
Anzeige