updated word query

  • Thread starter Thread starter Vicky
  • Start date Start date
V

Vicky

Hi,

Further to a reply I recieved earlier I tested what was
written and produced the following

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click

Dim appWord As New Word.Application
appWord.Visible = True 'Makes Word
visible
appWord.Documents.Add() 'Creates
New Blank Doc

Dim str As String = "Text"
Dim rng As Word.Range = appWord.Range(Start:=0, End:=0)

rng.Text = str
rng.Select=()


End Sub

the script itself will open word, however it wont paste and
throws out the following:

An unhandled exception of type
'System.MissingMemberException' occurred in
microsoft.visualbasic.dll

Additional information: Public member 'Range' on type
'ApplicationClass' not found.

I was wondering what it was likely I was doing wrong

Many thanks for any help

Vicky
(Learning fast, but not fast enough)
 
You need to specify the range on the current document, not the application.
Like this:

Dim theDocument As Word.Document

theDocument = appWord.Documents.Add()

Dim str As String = "Text"
Dim rng As Word.Range = theDocument .Range(Start:=0, End:=0)

rng.Text = str
rng.Select=()
 
Hi robin,

thankyou

vicky
-----Original Message-----
You need to specify the range on the current document, not the application.
Like this:

Dim theDocument As Word.Document

theDocument = appWord.Documents.Add()

Dim str As String = "Text"
Dim rng As Word.Range = theDocument .Range(Start:=0, End:=0)

rng.Text = str
rng.Select=()








.
 
Back
Top