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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

752 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