Prozeen 0 Junior Poster in Training

I've got a problem with Word. My program can open Word, put text into it, save it and close it. But if I try to use Word again (without closing my program) I get an error...

Run time error '-2147023174 (800706ba)':
Automation error

The error that is highlighted in the code is listed below (wdPageBreak = 7)...

Selection.InsertBreak Type:=wdPageBreak

So, I'm thinking I am not closing Word correctly. Any ideas? Thanks.

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = New Word.Application
wrdApp.Visible = False
Set wrdDoc = wrdApp.Documents.Add

'Add text.
'Add text.

wrdDoc.SaveAs comdia.filename
wrdDoc.Saved = True
wrdDoc.Close
Set wrdDoc = Nothing
wrdApp.Quit
Set wrdApp = Nothing
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.