HI friends,
Can you please guide me how to transafer data from excel file to Word document using VBA script/Macro.
Thanks!!
Hi Welcome to the forum,
Try this codeCode:Sub LinkWorkBookToMsWord() 'This code will Paste an Excel range to Ms_Word and name it, and it will be linked to the excel workbook Dim xlTable As Object Dim r As Range Set r = Worksheets("Sheet1").Range("A1", Range("B65536").End(xlUp)) Set xlTable = CreateObject("Word.Application") 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
Thank you Dave..
I will try this code.
Dave,
I think your code might end up in an error aswill only work when Sheet1 is ActiveSheet. I think it is better to do it as such:Code:Set r = Worksheets("Sheet1").Range("A1", Range("B65536").End(xlUp))
Code:Sub SetRng() Dim r As Range 'Set r = Worksheets("Sheet1").Range("A1", Range("B65536").End(xlUp)) With Worksheets("Sheet1") Set r = Range(.Range("A1"), .Range("B65536").End(xlUp)) End With End Sub
Looking for great solutions but hate waiting?
Seach this Forum through Google
www.Google.com (e.g. +multiple +IF site:excelforum.com/excel-general/ )
www.Google.com (e.g. +fill +combobox site:excelforum.com/excel-programming/ )
Ave,
Ricardo
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks