Microsoft Word Copy Paste As Picture VBA code example

Microsoft Word Copy Paste As Picture VBA code example


This is a method which works like Copy method where selection gets copied into the clipboard and can be pasted in other sources. Consider given table in the document which we will copy paste as picture just below to it:

Source document

Code example

Public Sub CopyAsPictureExample()
    'Bind document object reference
    Dim oDocument As Document
    Set oDocument = ActiveDocument
    'Bind table object
    Dim oTable As Table
    Set oTable = oDocument.Tables(1)
    oTable.ApplyStyleHeadingRows = True
    'Select table
    'Bind selection object reference
    Dim oSelection As Selection
    Set oSelection = Selection
    'perform copy paste
    oSelection.Collapse Direction:=wdCollapseEnd
    oSelection.PasteSpecial DataType:=wdPasteEnhancedMetafile
    'Memory cleanup
    Set oSelection = Nothing
    Set oTable = Nothing
    Set oDocument = Nothing
End Sub


Next >> Understand Comments Vs. Note Text in Excel

Leave a Reply

Your email address will not be published.