VBA Excel - Exemplos de Copiar e Colar - 05

Este código colará o intervalo do MS Excel num documento do MS Word, deixando-o interligado ao MS Excel.



Sub LinkWorkBookToMsWord()
    Dim xlTable As Object
    Dim r As Range
   

    Set r = Worksheets("Sheet1").Range("A1", Range("B65536").End(xlUp))

    Set xlTable = CreateObject("Word.Application")

    Let xlTable.Visible = True
    r.Copy
    xlTable.documents.Add
    xlTable.Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:= _
                                   wdInLine, DisplayAsIcon:=False
    xlTable.activedocument.SaveAs ThisWorkbook.Path & "/" & "LinkedToWord.doc"
    xlTable.documents.Close
    xlTable.Quit
    Application.CutCopyMode = False
End Sub

Tags: Excel, VBA, copy, paste, MS Word, Word,


Inline image 1

Nenhum comentário:

Postar um comentário

diHITT - Notícias