Excel to Word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hogg
    New Member
    • Nov 2008
    • 1

    Excel to Word

    Hey all!

    I'm having a problem with transferring data from excel to word. I've got the majority of the code done where I can select and copy the cells in excel and paste the cells as required into word. However I can't specify where I want the data to be inserted into word. When this goes into full operation there will be a lot of data to be transferred. I guess I need to use words bookmarks but I don't want to loose the paste special -> link function.

    Any ideas?

    Code so far:
    Code:
    Sub Excel_to_Word()
    Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet
        Application.ScreenUpdating = False
        Application.StatusBar = "Creating new document..."
        Set wdApp = New Word.Application
        Set wdDoc = wdApp.Documents.Open("c:\Doc1.doc")
         
        wdApp.Visible = True
         
        Sheets("Project Data").Range("B1:F16").Copy
        
        wdApp.Selection.PasteSpecial Link:=True, DataType:=wdPasteRTF
    
    End Sub
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hey there friend!

    This looks to be the same code you have, but it looks your's is missing somehting:

    [CODE=VB]
    Sub RangeToDocument ()
    ' Set a VBE reference to Microsoft Word Object Library

    Dim WDApp As Word.Applicatio n
    Dim WDDoc As Word.Document

    ' Make sure a range is selected
    If Not TypeName(Select ion) = "Range" Then
    MsgBox "Please select a worksheet range and try again.", vbExclamation, _
    "No Range Selected"
    Else
    ' Reference existing instance of Word
    Set WDApp = GetObject(, "Word.Applicati on")
    ' Reference active document
    Set WDDoc = WDApp.ActiveDoc ument
    ' Reference active slide

    ' Copy the range
    Selection.Copy

    ' Paste the range
    WDApp.Selection .PasteSpecial Link:=False, DataType:=wdPas teRTF, _
    Placement:= wdInLine, DisplayAsIcon:= False


    ' Clean up
    Set WDDoc = Nothing
    Set WDApp = Nothing
    End If

    End Sub

    [/CODE]

    I bold the portion I think should do the trick for ya...

    Let us know if that worked:-)

    Whoops, bold does not work, been away too long. Look where you need to paste the data, perhaps you can use it to fit your needs.

    Later!
    Last edited by Dököll; Nov 11 '08, 02:17 AM. Reason: added remark...

    Comment

    Working...