Muhammad Nasir Mahmood
New Member
- Joined
- Nov 29, 2024
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
I have two files: one Excel file and one PowerPoint file. I am exporting data from Excel to PowerPoint and then generating a PDF file for each record.
The VBA code is working fine, but there is one issue. It simply saves the document as a PDF.
However, I want to export the document from PowerPoint using the following steps:
When the option is unchecked, the word "NO" is displayed in front of TAGGED PDF.
Please help to resolve the issue.
Thanks
NOTE: I AM NOT AN EXPERT IN CODING
Code is:
Sub ExportPPTtoPDF()
Dim pptApp As Object
Dim pptPres As Object
Dim pptSlide As Object
Dim shape As Object
Dim excelSheet As Worksheet
Dim row As Integer
Dim pdfPath As String
Dim pptFilePath As String
Dim fileName As String
Dim folderPath As String
Dim selectedFolder As String
Dim shapeName As String
Dim slideIndex As Integer
Dim slide As Object
Dim shapeFound As Boolean
' Set Excel Worksheet "Do not delete"
Set excelSheet = ThisWorkbook.Sheets("Do not delete") ' Sheet name "Do not delete"
' Ask user to open PowerPoint file
pptFilePath = Application.GetOpenFilename("PowerPoint Files (*.pptx), *.pptx", , "Select PowerPoint File")
If pptFilePath = "False" Then Exit Sub ' Exit if user cancels file dialog
' Open PowerPoint application and the presentation
Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Open(pptFilePath)
' Ask user to select the destination folder to save PDF
selectedFolder = Application.GetSaveAsFilename("Select destination to save PDF", , , "PDF Files (*.pdf), *.pdf")
If selectedFolder = "False" Then Exit Sub ' Exit if user cancels file dialog
folderPath = Left(selectedFolder, InStrRev(selectedFolder, "\") - 1)
' Loop through each row starting from row 2 (assuming row 1 is header)
For row = 2 To excelSheet.Cells(excelSheet.Rows.Count, "B").End(xlUp).row
' Get the name of the PDF from column Q
fileName = excelSheet.Cells(row, 17).Value ' Column Q
' Loop through all slides in the PowerPoint presentation
For slideIndex = 1 To pptPres.Slides.Count
Set pptSlide = pptPres.Slides(slideIndex)
' Loop through each shape on the current slide
For Each shape In pptSlide.Shapes
' Match the shape name case-insensitively
If LCase(shape.Name) = "data1" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 2).Value ' Data1 (B2)
ElseIf LCase(shape.Name) = "data2" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 3).Value ' Data2 (C2)
ElseIf LCase(shape.Name) = "data3" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 4).Value ' Data3 (D2)
ElseIf LCase(shape.Name) = "data4" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 5).Value ' Data4 (E2)
End If
Next shape
Next slideIndex
' Export the presentation to PDF with the selected file name and path
pptPres.SaveAs folderPath & "\" & fileName & ".pdf", 32 ' Save as PDF (32 is for PDF format)
' Message to confirm PDF saved
MsgBox "PDF saved as: " & folderPath & "\" & fileName & ".pdf"
Next row
' Close PowerPoint presentation without saving
pptPres.Close
pptApp.Quit
End Sub
The VBA code is working fine, but there is one issue. It simply saves the document as a PDF.
However, I want to export the document from PowerPoint using the following steps:
- Use the Export function.
- Select Create PDF/XPS Document.
- Click Create PDF/XPS.
- In the Options, uncheck the box for Document structure tags for accessibility (this option is checked by default).
When the option is unchecked, the word "NO" is displayed in front of TAGGED PDF.
Please help to resolve the issue.
Thanks
NOTE: I AM NOT AN EXPERT IN CODING
Code is:
Sub ExportPPTtoPDF()
Dim pptApp As Object
Dim pptPres As Object
Dim pptSlide As Object
Dim shape As Object
Dim excelSheet As Worksheet
Dim row As Integer
Dim pdfPath As String
Dim pptFilePath As String
Dim fileName As String
Dim folderPath As String
Dim selectedFolder As String
Dim shapeName As String
Dim slideIndex As Integer
Dim slide As Object
Dim shapeFound As Boolean
' Set Excel Worksheet "Do not delete"
Set excelSheet = ThisWorkbook.Sheets("Do not delete") ' Sheet name "Do not delete"
' Ask user to open PowerPoint file
pptFilePath = Application.GetOpenFilename("PowerPoint Files (*.pptx), *.pptx", , "Select PowerPoint File")
If pptFilePath = "False" Then Exit Sub ' Exit if user cancels file dialog
' Open PowerPoint application and the presentation
Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Open(pptFilePath)
' Ask user to select the destination folder to save PDF
selectedFolder = Application.GetSaveAsFilename("Select destination to save PDF", , , "PDF Files (*.pdf), *.pdf")
If selectedFolder = "False" Then Exit Sub ' Exit if user cancels file dialog
folderPath = Left(selectedFolder, InStrRev(selectedFolder, "\") - 1)
' Loop through each row starting from row 2 (assuming row 1 is header)
For row = 2 To excelSheet.Cells(excelSheet.Rows.Count, "B").End(xlUp).row
' Get the name of the PDF from column Q
fileName = excelSheet.Cells(row, 17).Value ' Column Q
' Loop through all slides in the PowerPoint presentation
For slideIndex = 1 To pptPres.Slides.Count
Set pptSlide = pptPres.Slides(slideIndex)
' Loop through each shape on the current slide
For Each shape In pptSlide.Shapes
' Match the shape name case-insensitively
If LCase(shape.Name) = "data1" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 2).Value ' Data1 (B2)
ElseIf LCase(shape.Name) = "data2" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 3).Value ' Data2 (C2)
ElseIf LCase(shape.Name) = "data3" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 4).Value ' Data3 (D2)
ElseIf LCase(shape.Name) = "data4" Then
shape.TextFrame.TextRange.Text = excelSheet.Cells(row, 5).Value ' Data4 (E2)
End If
Next shape
Next slideIndex
' Export the presentation to PDF with the selected file name and path
pptPres.SaveAs folderPath & "\" & fileName & ".pdf", 32 ' Save as PDF (32 is for PDF format)
' Message to confirm PDF saved
MsgBox "PDF saved as: " & folderPath & "\" & fileName & ".pdf"
Next row
' Close PowerPoint presentation without saving
pptPres.Close
pptApp.Quit
End Sub