0

I am currently creating a document that will take the format and text from a MS Word document and paste it into a text box in a PowerPoint template. I have looked all over to see how this can be done and haven't found much. Any help would be much appreciated!!

Public Sub CommandButton1_Click()
Dim pptApp As Object
Dim pptPres As String
Dim folderPath, file As String

    folderPath = ActiveDocument.Path & Application.PathSeparator
    file = "Huntington_Template.pptx"
    pptApp.Visible = True
    pptApp.presentations.Open (folderPath & file)

    ActiveDocument.Bookmarks("Update_Image").Range.Copy 'text box to copy in MS WS
    'not sure what to do next?

End Sub
0

1 Answer 1

2

I notice a few errors in your code:

  • You haven't created an instance of PowerPoint.Application
  • You have declared pptPres as String but probably should be As Object to represent a Powerpoint.Presentation object
  • You do not make any assignment to pptPres

This would be easier to do by the Shape's .Name but I think this will work. I have made some other changes to declare some more variables in addition to those above.

Sub Test()
Dim pptApp As Object    'PowerPoint.Application
Dim pptPres As Object   'PowerPoint.Presentation
Dim folderPath As String, file As String
Dim bk As Bookmark
Dim doc As Document
Dim wdRange As Range
Dim shpTextBox as Object 'PowerPoint.Shape

    '## As a matter of prefernce I use variable rather than "ActiveDocument"
    Set doc = ActiveDocument

    '## Use a variable for the bookmark
    Set bk = doc.Bookmarks("Update_Image")

    '## Assign to the pptApp Application Object
    Set pptApp = CreateObject("PowerPoint.Application")

    folderPath = doc.Path & Application.PathSeparator
    file = "Huntington_Template.pptx"

    pptApp.Visible = True
    '## assign to the pptPres Presentation Object
    Set pptPres = pptApp.presentations.Open(folderPath & file)

    '## Select the bookmark so we can copy it
    bk.Select

    '## Copy it
    Selection.Copy


    'Note: ensure you are at the correct slide location

    '## Assign to the shpTextBox & select it:
    Set shpTextBox = pptPres.Slides(1).Shapes("Text Box 2")
    shpTextBox.Select

    '## Paste in to PPT
    pptApp.CommandBars.ExecuteMso "PasteSourceFormatting"


End Sub

NOTE This pastes directly to the slide, if you need to put it in a specific textbox/shape in the PowerPoint slide, let me know. I am fairly certain that could be done by specifying the shape name in PowerPoint/etc.

I've seen the CommandBars.ExecuteMso method before but it is not very well-documented compared to many other methods. The Application.CommandBars property reference has nary a mention of the ExecuteMso method, which I found some information about here:

http://msdn.microsoft.com/en-us/library/office/ff862419(v=office.15).aspx

This method is useful in cases where there is no object model for a particular command. Works on controls that are built-in buttons, toggleButtons and splitButtons.

You'll need a list of idMso parameters to explore, which come as part of a rather large downloadable file, current for Office 2013 I believe:

http://www.microsoft.com/en-us/download/details.aspx?id=727

6
  • This is awesome! Thank you! I am trying to paste the contents directly into a textbox on the slide versus directly to the slide. Can you help with this as well? I did add the PowerPoint 14.0 reference library so I now have access to those methods.
    – James
    Jul 9, 2014 at 13:45
  • When naming a shape/textbox in PowerPoint, is that done through the Selection Pane in the Formatting tab?
    – James
    Jul 9, 2014 at 13:47
  • Yes, I was just about to mention that. If you don't know the name, use the Selection pane to see the name (and edit it if needed). Jul 9, 2014 at 13:48
  • BTW, updated my answer above to paste to specific shape in PowerPoint :) Jul 9, 2014 at 13:58
  • Do let me know if this works for you, and if so, please consider accepting the answer so that others with similar Q's in the future may benefit from this. Jul 9, 2014 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.