VBA : Convert PPT to Ms Word

Susanto3311
3StarLounger
Posts: 251
Joined: 17 Feb 2022, 05:16

VBA : Convert PPT to Ms Word

Post by Susanto3311 »

hi all.
i'm looking for code to convert ppt slide to word.
the below code not working well

Code: Select all

Sub CopyText()
    ' for ms word
    Dim wdApp As Word.Application, wdDoc As Word.Document
    Set wdApp = GetObject(, "Word.Application")
    If wdApp Is Nothing Then Set wdApp = New Word.Application
    Set wdDoc = wdApp.ActiveDocument
    
    Dim sld As Slide
    Dim shp As Shape
    Set sld = Application.ActiveWindow.View.Slide
    Dim isTitle As Boolean
    Dim showTitle As Boolean
    
    For Each sld In ActivePresentation.Slides
    
        isTitle = False
        showTitle = True
        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If shp.TextFrame.HasText Then
                    If LastTitle = shp.TextFrame.TextRange.Text Then
                        showTitle = False
                    End If
                    shp.TextFrame.TextRange.Copy
                    If Not isTitle Then
                        If showTitle Then
                            wdApp.Selection.Style = wdDoc.Styles("Heading 1")
                            wdApp.Selection.PasteAndFormat wdPasteDefault
                            wdApp.Selection.Move
                            'wdApp.Selection.Paste
                            'wdApp.Selection.PasteSpecial DataType:=wdPasteText
                            LastTitle = shp.TextFrame.TextRange.Text
                            
                        End If
                        isTitle = True
                    Else
                        wdApp.Selection.TypeParagraph
                        wdApp.Selection.PasteAndFormat wdPasteDefault
                        wdApp.Selection.Move
                        
                    End If
                    
                End If
            Else
                shp.Copy
                wdApp.Selection.PasteAndFormat wdPasteDefault
                'wdApp.Selection.Paragraphs.Add
                wdApp.Selection.Move
                
                wdDoc.Content.InsertAfter (vbCrLf)
             End If
        Next shp
    
    Next sld
    End Sub
    
End Sub
i hope someone would help me out or maybe have other code to convert ppt into ms word

susant

Susanto3311
3StarLounger
Posts: 251
Joined: 17 Feb 2022, 05:16

Re: VBA : Convert PPT to Ms Word

Post by Susanto3311 »

hi charles..

i don't understand what you ask "have you tried Documents.Open("MyFile.pdf")?
but i want to convert into ms word.

User avatar
HansV
Administrator
Posts: 79671
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Convert PPT to Ms Word

Post by HansV »

Charles misread your post, so he removed his reply.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 79671
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Convert PPT to Ms Word

Post by HansV »

You could export the presentation to handouts - that is a Word document.

S1798.png

Unfortunately, creating a handout is not supported in PowerPoint VBA.
An alternative would be to export to PDF. Word can open PDF files.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 79671
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Convert PPT to Ms Word

Post by HansV »

I have moved this thread from the Word forum to the PowerPoint forum since it is about PowerPoint VBA.
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 251
Joined: 17 Feb 2022, 05:16

Re: VBA : Convert PPT to Ms Word

Post by Susanto3311 »

hi hans,thank you nice solution