VBA在活动的Word文档光标处粘贴选中的Excel Chart图表

2015-05-13 0 933
VBA在活动的Word文档光标处粘贴选中的Excel Chart图表
Sub ChartToDocument()
' Set a VBE reference to Microsoft Word Object Library

Dim WDApp As Word.Application
Dim WDDoc As Word.Document

' Make sure a chart is selected
If ActiveChart Is Nothing Then
    MsgBox "Please select a chart and try again.", vbExclamation, _
        "No Chart Selected"
Else
    ' Reference existing instance of Word
    Set WDApp = GetObject(, "Word.Application")
    ' Reference active document
    Set WDDoc = WDApp.ActiveDocument
    
    ' Copy chart as a picture
    ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
        Format:=xlPicture

    ' Paste chart at cursor position
    WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
        Placement:=wdInLine, DisplayAsIcon:=False

    ' Clean up
    Set WDDoc = Nothing
    Set WDApp = Nothing
End If

End Sub

遇见资源网 ASP/Basic VBA在活动的Word文档光标处粘贴选中的Excel Chart图表 http://www.ox520.com/13431.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务