2015-04-21 68 views
0

嗨,我是第一次海報,VBA貼msoChart到PowerPoint 2010

我試圖粘貼msoChart對象從剪貼板數據嵌入到PowerPoint 2010使用VBA。 (在Excel 2010中創建的圖表)。

我可以找到的唯一示例涉及將圖表鏈接到Excel文件或創建msoEmbeddedOLEObject。

如果我手動在PowerPoint 2010中粘貼,我會得到一個粘貼選項來「嵌入工作簿」。但在手動「選擇性粘貼」中不可用。

因此,看起來除了粘貼圖表之外,還需要一些東西。但我不確定那是什麼或如何去做。

我已經試過是

Sub PasteExample() 
Dim Sld As Slide 
Dim Shp As ShapeRange 

    Set Sld = ActiveWindow.View.Slide 

    '# This pastes clipboard content as a linked chart 
    Set Shp = Sld.Shapes.Paste 
End Sub 

Sub PasteExample2() 
Dim Sld As Slide 
Dim Shp As ShapeRange 

    Set Sld = ActiveWindow.View.Slide 

    '# This option does not work, object is still linked 
    'Set Shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteDefault, Link:=msoFalse) 

    '# This option does not work, object is still linked 
    'Set Shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteShape, Link:=msoFalse) 

    '# I'm not after OLEObjects 
    'Set Shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoFalse) 
End Sub 

非常感謝,如果你能提供一些線索。

回答

0

我們看不出有什麼要複製,以及如何,PLZ加入代碼,如果問題不解決

這裏有PpPasteDataType的,您可以用PasteSpecial的在PowerPoint中使用的成員:通常

members of PpPasteDataType ,我使用的代碼爲基礎,它應該幫助你:

Sub Export_to_Ppt() 
' 
Dim Ppt As PowerPoint.Application, _ 
    Pres As PowerPoint.Presentation 

Set Ppt = CreateObject("PowerPoint.Application") 
Set Pres = Ppt.Presentations.Open("I:\Template DTC.potx") 

Ppt.Visible = True 

Sheets("Graph1").ActiveChart.ChartArea.Copy 

Pres.Slides.Add Index:=Pres.Slides.Count + 1, Layout:=ppLayoutTitleOnly 
'Pres.Slides(Pres.Slides.Count).Shapes.Paste 
Pres.Slides(Pres.Slides.Count).Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile, Link:=False 

Pres.Slides(Pres.Slides.Count).Shapes.Title.TextFrame.TextRange.Text = "Chart Title" 


Pres.SaveAs _ 
    Filename:="I:\TestNaz.ppt", _ 
    FileFormat:=ppSaveAsOpenXMLPresentation 

Set Ppt = Nothing 
Set Pres = Nothing 

End Sub 
+0

用戶將創建一個圖表(任何Excel圖表)將其手動複製到剪貼板(Crtl + C)。我使用的Powerpoint解決方案將插入剪貼板中的圖表並嵌入數據,但不是嵌入式對象而不是鏈接圖表。 –

+0

好的,你應該使用這個:'Pres.Slides(Pres.Slides.Count).Shapes.PasteSpecial DataType:= ppPasteEnhancedMetafile,Link:= False' – R3uK

+0

這將只是插入一張圖片。我非常感謝你的努力,但似乎你還沒有閱讀我發佈的代碼上面的問題。 –

0

我試圖重現你的榜樣與PowerPoint 2013年我無法重現你的行爲描述。

前提條件:我將Excel 2013圖表複製到剪貼板(只是圖表,而不是整個工作表或其他任何東西)。

調用要麼Sld.Shapes.PasteSld.Shapes.PasteSpecial(DataType:=ppPasteDefault,Link:=msoFalse)將插入一個msoChart到PowerPoint:

Set shp = Sld.Shapes.Paste 
MsgBox shp.Type ' returns 3 that is msoChart 

Set shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteDefault, Link:=msoFalse) 
MsgBox shp.Type 'returns 3 that is msoChart 

這些圖表的格式正確,在當前的PowerPoint的風格,我可以用鼠標右鍵單擊其中的數據進行編輯。

尤其是,它們是嵌入的,沒有鏈接。


爲了比較,我也試過:

Set shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoFalse) 
MsgBox shp.Type ' returns 7 that is msoEmbeddedOLEObject 

Set shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoTrue) 
MsgBox shp.Type ' returns 10 that is msoLinkedOLEObject 

Set shp = Sld.Shapes.PasteSpecial(DataType:=ppPasteDefault, Link:=msoTrue) 
MsgBox shp.Type 'returns 10 that is msoLinkedOLEObject 

當我右鍵單擊那些在PowerPoint中,再有就是在菜單項操縱「Worksheed對象」分別是「鏈接Worksheed對象」。

所以要麼我誤解了你的意思是「鏈接」,或者在2010年有一個錯誤,或者你的剪貼板有不同的東西。

+0

聽起來好像有一些改進/在Powerpoint 2013中修復了錯誤。 不幸的是,我現在沒有辦法來驗證這一點。 –

0

我的確遇到了另一種形式的解決方案。 圖表在剪貼板中。

執行以下線在PowerPoint 2010中

Application.CommandBars.ExecuteMso "PasteExcelChartDestinationTheme" 

它給了我正是我一直在後。