简体   繁体   English

如何从MS Word复制/粘贴文本框到Powerpoint幻灯片?

[英]How to Copy/Paste text box from MS Word to Powerpoint slide?

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. 我当前正在创建一个文档,它将采用MS Word文档中的格式和文本并将其粘贴到PowerPoint模板的文本框中。 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

I notice a few errors in your code: 我注意到您的代码中存在一些错误:

  • You haven't created an instance of PowerPoint.Application 您尚未创建PowerPoint.Application的实例
  • You have declared pptPres as String but probably should be As Object to represent a Powerpoint.Presentation object 您已将pptPres声明为String,但可能应As Object代表Powerpoint.Presentation对象
  • You do not make any assignment to pptPres 您没有对pptPres进行任何分配

This would be easier to do by the Shape's .Name but I think this will work. 通过Shape的.Name会更容易做到这一点,但我认为这会起作用。 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. 注意这会直接粘贴到幻灯片上,如果您需要将其放入PowerPoint幻灯片中的特定文本框/形状中,请告诉我。 I am fairly certain that could be done by specifying the shape name in PowerPoint/etc. 我相当确定可以通过在PowerPoint / etc中指定形状名称来完成。

I've seen the CommandBars.ExecuteMso method before but it is not very well-documented compared to many other methods. 我以前见过CommandBars.ExecuteMso方法,但是与许多其他方法相比,它的文档记录不是很好。 The Application.CommandBars property reference has nary a mention of the ExecuteMso method, which I found some information about here: Application.CommandBars 属性参考没有提到ExecuteMso方法,我在这里找到了一些信息:

http://msdn.microsoft.com/en-us/library/office/ff862419(v=office.15).aspx http://msdn.microsoft.com/zh-CN/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. 适用于内置按钮,toggleButtons和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: 您需要探索一个idMso参数列表, 这些参数是一个相当大的可下载文件的一部分,该文件是Office 2013的最新版本,我相信:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 MS word 复制 15 行并将其粘贴到 powerpoint 幻灯片中的每张幻灯片? - How to copy 15 lines from MS word and paste it to each slide in powerpoint slide? 如何将粘贴数据范围从Excel复制到PowerPoint幻灯片 - How to Copy paste data range from Excel to powerpoint slide 从 MS Word,如何使用 VBA 在 Powerpoint 中添加幻灯片 - From MS Word, how can I add a slide in Powerpoint using VBA 如何将文本从 Word 文档复制到 PowerPoint 并进行演示 - How copy Text from Word document to PowerPoint and make a Presentation 如何将模板从另一个 PowerPoint 复制到幻灯片中? - How to copy template into slide from another PowerPoint? VBA POWERPOINT:将带有格式的文本从Powerpoint复制到单词 - VBA POWERPOINT: Copy text with formatting from powerpoint to word 从Excel VBA修复PowerPoint幻灯片中的文本框(在右侧) - Fix a text box (at the right) in PowerPoint slide from Excel VBA 如何以编程方式将图片从Word复制到Powerpoint? - How to copy picture from Word to Powerpoint programmatically? 为 Powerpoint 的每张幻灯片自动生成文本框中的文本 - Automating the text in a text box for each slide of a Powerpoint Excel 宏从 Excel 工作表复制表格并将其粘贴到 PowerPoint 幻灯片中,灵活地决定哪些列和行 - Excel Macro to copy a table from Excel Sheet and paste it in a PowerPoint Slide with flexibilty to decide which columns and rows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM