VBA code to Copy a Range Into Word

  • Hi all, new to the forum, please be gentle if I have made a faux pas!


    Would really appreciate some help with a problem that I am sure most of you would find laughably easy.


    I am trying to create a Macro that will: Select a range, copy it, launch word and then paste.


    It isn't neccessary to save the new word document or provide a message that the operation has been completed.


    I have tried to use some code provided by "Jack in the UK" as follows:



    Unfortunately though, all this managed to do for me though was to launch Word and show me a document that said "Jack - Test from Excel". And yes, I did correct the range!


    If anyone can hlep me, would be very grateful indeed.


    Many thanks,
    Rich.

  • Re: VBA code to Copy a Range Into Word


    You can add your If staement if you wish, but the code is actually quite simple. You need to set a reference to the MS Word object library in the Excel VBE


    [vba]
    Option Explicit


    Sub Excel_to_Word()
    Dim appWord As Word.Application


    Set appWord = New Word.Application


    appWord.Visible = True


    Range("A1:A20").Copy


    appWord.Documents.Add.Content.Paste


    End Sub
    [/vba]


    Hope this helps.


    Can you use the CODE tags when posting code please. Thanks

  • Re: VBA code to Copy a Range Into Word


    WillR,


    Many thanks for your very prompt response, have managed to get your code to work for me, however, I think it was you telling me to set a reference to the MS Word object library in the Excel VBE that was of the greatest use! I had no idea that this was necessary, or even existed! It wasn't until I managed to do this that your code worked for me!


    Sorry for not using the CODE tabs first time around.


    Many thanks again,
    Rich.
    :thanx:

  • Re: VBA code to Copy a Range Into Word


    I tried to use this code because I'm trying to copy many tables into one word document. But every time the code runs, it makes a new word document. How can I make it so all the tables go into the same Word document?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!