+ Reply to Thread
Results 1 to 6 of 6

Copy excel contents to word

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2007
    Posts
    39

    Copy excel contents to word

    Hi -
    Is it possible to automate the process of copying cells from excel to a word documet? For example: I have first name and last names in two colums in excel and I would like to copy the first and last names to a Word template.

    Please suggest!

    Thanks,
    Ritu

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Try this!
    Sub wrdstart()
    Dim appwd As Object
    On Error GoTo notloaded
    Set appwd = GetObject(, "Word.Application")
    notloaded:
        If Err.Number = 429 Then
            Set appwd = CreateObject("Word.Application")
        End If
    appwd.Visible = True
    On Error GoTo 0
    With appwd
    .documents.Add
    .Selection.TypeText Text:=vbTab
    Range("A1:B1").Copy
    
    .Selection.Paste
    
    End With
    End Sub
    Regards,
    Simon

  3. #3
    Registered User
    Join Date
    02-01-2007
    Posts
    39

    GetObject function

    Hi Simon,

    This works great but I do have another question. When I call the GetObject function as follows, it does not open my word document. Do you know why this would be? Am I missing something?


    Set appwd = GetObject("c:\WordName.doc")

    Thanks,
    Ritu

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Try this:
    Dim appwd As Object
    On Error GoTo notloaded
    Set appwd = GetObject(, "Word.Application")
    Set wrdDoc = appwd.Documents.Open("C:WordName.doc") 
    notloaded:
        If Err.Number = 429 Then
            Set wrdDoc = CreateObject("Word.Application")
        End If
    wrdDoc.Visible = True
    On Error GoTo 0
    With wrdDoc
    .Selection.TypeText Text:=vbTab
    Range("A1:B1").Copy
    
    .Selection.Paste
    
    End With
    Regards,
    Simon

  5. #5
    Registered User
    Join Date
    02-01-2007
    Posts
    39

    Run time error 438

    Thank you for helping me with this..

    I actually get the following Run Time error:

    Run time error: '438'
    Object doesn't suppport this property or method.

    Any ideas why?

    Thanks,
    Ritu

  6. #6
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Which line does the code stop on?, i didn't test the code just knocked it up!

    Regards,
    Simon

+ Reply to Thread

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.6.0 RC 1