Creating a Word document from Excel

vba Denmark
  • 18 years ago

    I need to pass information from an Excel sheet to standard Word documents. I've come up with various solutions, but each solution has it's problem. The best solution so far is concatenating various cells in the sheet and copying the concatenated cell as simple text to Word, by letting the Open Event trigger the code. But somehow it keeps messing up. Does someone have a solution?


    Thomas Andersen

  • 18 years ago

    First thing you need to do is to reference the Word object model, as that will make it simpler (Tools>References).


    In this example I've copied the cell A1, but that could be your concatenated text.


       Range("A1").Copy
       Application.ActivateMicrosoftApp xlMicrosoftWord
       ActiveDocument.Range.PasteSpecial DataType:=wdPasteText


    You then activate Microsoft Word (or open it, if it is not already open) and use the Word object model to paste the contents (hence the need for the reference).  I have used the paste text option of paste special as you required simple text.


    This is probably not the final solution for you, but should set you off in the right direction.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks