Discussion Locked

Adding text in MS Word frm VisualBasic

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi,
can any one plz tell me how to add text in ms word from vb?? [using same vb macro commands as our word macro produces....]

m trying to add text in a word document from VB, initializing the doc is error free, but when i try to use "b" (selection object) the error appears... below is my code...

------------------------------------------
Dim a As New Word.Document
Dim b As Word.Selection
-- or -- Set b = Word.Selection

b.TypeText "asdf"
[Error: object variable or with block not set]

a.SaveAs ("c:\2.doc")
-----------------------------------------------

wat to do now??
(this code is of form's load event)...
the reference of ms word is also added in project references....

5 replies

by glen_mcleod

Dim the variable b as a Word.Selection, but you have to set it equal to a.Selection. Otherwise, your b variable doesn't point to any document.

Dim b as Word.Selectio
Set b = a.Selection

Glen

This discussion is closed to new replies.