+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    12-22-2009
    Location
    Pune, India
    MS-Off Ver
    Excel 2003
    Posts
    30

    Transfer data from Excel to word using VBA script

    HI friends,

    Can you please guide me how to transafer data from excel file to Word document using VBA script/Macro.

    Thanks!!

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007
    Posts
    6,259

    Re: Trnsfrng data frm Excel to word using VBA script

    Hi Welcome to the forum,

    Try this code
    Code:
    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
    Dave


  3. #3
    Registered User
    Join Date
    12-22-2009
    Location
    Pune, India
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Trnsfrng data frm Excel to word using VBA script

    Thank you Dave..

    I will try this code.

  4. #4
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Trnsfrng data frm Excel to word using VBA script

    Dave,

    I think your code might end up in an error as
    Code:
    Set r = Worksheets("Sheet1").Range("A1", Range("B65536").End(xlUp))
    will only work when Sheet1 is ActiveSheet. I think it is better to do it as such:
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0