How Do I Late Bind This...

Trikageon

Board Regular
Joined
Apr 29, 2010
Messages
51
Hey all! I was wondering if anyone knew copy range G15:H600 from excel to word, paste it, and then copy it back from word to excel in the exact same location from whence it came - all using late binding. I've been trying everything I can think of, but I have very little experience in this regard. If you could just write back code I could try, I would be ecstatic if something actually worked! Thanks in advance!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this - change file paths and names as required. But why do you need it to use late binding? Do you want to run it from a VBScript or JScript file?
Code:
Option Explicit

Sub Excel_Word_Copy()

    Dim exApp As Object, exWb As Object
    Dim wdApp As Object, wdDoc As Object, wdTable As Object
    
    'Open an existing Excel workbook
    
    Set exApp = CreateObject("Excel.Application")
    With exApp
        .Visible = True
        Set exWb = .Workbooks.Open("C:\Temp\Excel_Workbook2.xls", , False)
    End With

    'Open an existing Word document
    
    Set wdApp = CreateObject("Word.Application")
    With wdApp
        .Visible = True
        Set wdDoc = .Documents.Open("C:\Temp\Word_Document.doc")
    End With

    'Copy the Excel range to the clipboard
        
    exWb.Worksheets("Sheet1").Range("G15:H600").Copy

    'Paste it at the start of the Word document - the data is pasted as a table
    
    wdDoc.Content.Paste

    exApp.CutCopyMode = False

    'Copy the first table in the document - the table that has just been pasted from Excel
    
    Set wdTable = wdDoc.Tables(1)
    wdTable.Range.Copy
    
    'Paste it back to the Excel workbook starting at G15
    
    With exWb.Worksheets("Sheet1")
        .Range("G15:H600").Cells.ClearContents  'Not required, but proves Word data has been pasted
        .Range("G15").Select
        .Paste
    End With
    
    'Close document

    wdDoc.Close True
    wdApp.Quit

    'Close workbook

    exWb.Close True
    exApp.Quit

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,223
Messages
6,177,260
Members
452,765
Latest member
Erka Gizli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top