Help with VB and Word

N

News.Microsoft.com

I have a piece of code in my vb app that opens up a Word document and then
fills in bookmarks with fields from a vb form. The problem that I am having
is that the fields that I am filling in have underlines and as I fill in
text it is in insert mode and pushes the lines over and messes up the page
formating. How do I turn off insert mode form VB. Here is a sample of my
code.

Dim MyWord As Word.Application

Set MyWord = New Word.Application
With MyWord
.Visible = True
.Documents.Open ("c:\BuildingChangeForm.doc")
.ActiveDocument.bookmarks("BuildingName").Select
.Selection.TypeText USIComboRead(cmbBuilding)


Thanks in advance for any help anyone can offer.

Bill
 
C

Cindy M.

Hi News.Microsoft.com,
I have a piece of code in my vb app that opens up a Word document and then
fills in bookmarks with fields from a vb form. The problem that I am having
is that the fields that I am filling in have underlines and as I fill in
text it is in insert mode and pushes the lines over and messes up the page
formating. How do I turn off insert mode form VB. Here is a sample of my
code.
Taking your question literally:
Options.OverType = true

...and don't forget to save and reinstate the user's setting!

However, I usually wouldn't use the approach you propose. Using the Selection
object is inefficient, causes screen flicker and is generally unreliable.
Better would be to do something like this:
Dim doc as Word.Document
Set doc = MyWord.Documents.Open("filepath")
doc.Bookmarks("BuildingName").Range.Text _
= USIComboRead(cmbBuilding).Text

You just have to make sure that the bookmark in the form document was assigned
after SELECTING what should be replaced.
Dim MyWord As Word.Application

Set MyWord = New Word.Application
With MyWord
.Visible = True
.Documents.Open ("c:\BuildingChangeForm.doc")
.ActiveDocument.bookmarks("BuildingName").Select
.Selection.TypeText USIComboRead(cmbBuilding)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top