Consulting

Results 1 to 10 of 10

Thread: Excel to word

  1. #1

    Excel to word

    Hello All,

    Can anyone advise on copying and pasting from excel to word.
    Many thanks

    yours,
    Ed

  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    What do you need, specifically? I can normally copy from Excel and paste to Word quite easily...
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  3. #3
    Thanks for you reply.
    I apologies for not being clear.
    I would like to know the VBA code to copy and paste infomation from excel to word.
    Many thanks

    yours,
    Ed

  4. #4
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    OK, a true copy-paste between apps using code is tricky.

    Can you describe what you need to do in some detail?
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  5. #5
    MS Excel MVP VBAX Tutor
    Joined
    Mar 2005
    Posts
    246
    Location
    Quote Originally Posted by photon_ed
    I would like to know the VBA code to...
    Office applications come with a very handy tool called the Macro Recorder. Turn it on, then do manually what you want to do in code. The recorded code isn't perfect, because it captures a lot of mouse actions, such as activating and selecting objects, which are not strictly required. But it will get you started, and it will help with syntax.

    Go to Excel, turn on the macro recorder, and copy what you need to copy. Go to Word, turn on the macro recorder, and paste what you need pasted. You'll have to get some code to get Excel to work with the Word application; this might be a good place to start:

    http://peltiertech.com/Excel/XL_PPT.html

    Use the Excel code you recorded, and the Word code, keeping in mind that the Word code will need to be prefixed with a reference to the Word application, document, or other Word object.
    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com
    _______

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    for a range:
    [VBA]
    Sub CopyToWord()

    'This code requires a referece to the Word object model
    Dim Appword As New Word.Application
    Dim wdDoc As Word.Document

    Set Appword = CreateObject("Word.Application")
    Appword.Documents.Add

    Range("A15:B36").Copy

    Appword.Selection.Paste


    Appword.Visible = True

    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Many thanks for all the responds.

    Lucas: Visual Basic doesnt seem to like the line " Dim Appword As New Word.Application " and a popup message saying "Compile error: User-defined type not defined".
    Pelase advise.

    yours,
    Ed

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Ed
    You need to add a reference to Word in the VBE as the Comment line in the code states.
    Tools/References Microsoft Word xx Object Library.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    That is perfect!
    Many thanks to ALL.

    yours,
    Ed

  10. #10
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Quote Originally Posted by photon_ed
    Lucas: Visual Basic doesnt seem to like the line " Dim Appword As New Word.Application " and a popup message saying "Compile error: User-defined type not defined".
    Pelase advise.
    Ed,

    As Malcolm indicated, you needed to set a reference. You could have also used late binding, and eliminated the need to set a reference. (Late binding is especially useful if you think people with different versions of Word will use the code, as this can cause version conflicts if you use early binding.)

    [VBA]
    Sub CopyToWord()

    'This code requires a referece to the Word object model
    Dim Appword As Object 'Word.Application

    Set Appword = CreateObject("Word.Application")
    Appword.Documents.Add

    Range("A15:B36").Copy

    Appword.Selection.Paste


    Appword.Visible = True

    Set Appword = Nothing

    End Sub
    [/VBA]
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

Posting Permissions

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