Write content to a word document

Posted on 2005-03-04
Medium Priority
Last Modified: 2010-05-02

I have a string in a VB project that I'd like to write in to a word document. Can anyone help out??

I have the word document all set up in code but I just don't know how to write to it. Also, if anyone can point me to some articles about using Word from VB that would be cool

Question by:LFMSupport
  • 2
LVL 10

Accepted Solution

RichardCorrie earned 300 total points
ID: 13459701
the key to putting data into Word is the Range object; in effect evrything boils down to a range.  You can then add/replace text within the range.

so try:

dim objWord as word.application
dim wrdDoc as word.document
dim wrdRange as word.range

set objword = new word.application
set wrddoc = objword.documents.add

set wrdrange = wrddoc.content

wrdrange.collapse wdCollapseend

wrdrange.insert after "Hello World"

objword.visible = true

set wrddoc = nothing
set objword = nothing

for more examples check the Word VBA help and MSDN site

LVL 32

Assisted Solution

Erick37 earned 300 total points
ID: 13459729
How To Automate Microsoft Word by Using Visual Basic to Create a New Document

Author Comment

ID: 13459837
Cheers guys.

Any objections if I split the points?

LVL 32

Expert Comment

ID: 13459932
Split away!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question