![](/img/trans.png)
[英]How to copy 15 lines from MS word and paste it to each slide in powerpoint slide?
[英]How to Copy/Paste text box from MS Word to Powerpoint slide?
我當前正在創建一個文檔,它將采用MS Word文檔中的格式和文本並將其粘貼到PowerPoint模板的文本框中。 我四處張望,看看該怎么做,卻發現不多。 任何幫助將非常感激!!
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
我注意到您的代碼中存在一些錯誤:
pptPres
聲明為String,但可能應As Object
代表Powerpoint.Presentation對象 pptPres
進行任何分配 通過Shape的.Name
會更容易做到這一點,但我認為這會起作用。 除上述變量外,我還進行了其他更改以聲明一些其他變量。
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
注意這會直接粘貼到幻燈片上,如果您需要將其放入PowerPoint幻燈片中的特定文本框/形狀中,請告訴我。 我相當確定可以通過在PowerPoint / etc中指定形狀名稱來完成。
我以前見過CommandBars.ExecuteMso
方法,但是與許多其他方法相比,它的文檔記錄不是很好。 Application.CommandBars
屬性參考沒有提到ExecuteMso
方法,我在這里找到了一些信息:
http://msdn.microsoft.com/zh-CN/library/office/ff862419(v=office.15).aspx
在沒有特定命令的對象模型的情況下,此方法很有用。 適用於內置按鈕,toggleButtons和splitButtons控件。
您需要探索一個idMso參數列表, 這些參數是一個相當大的可下載文件的一部分,該文件是Office 2013的最新版本,我相信:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.