mciing7912
Programmer
HI guys!
I have a VB application and I have a function there, for working with Microsoft Word.
this is the begin the code:
Set WordTemplate = CreateObject("WORD.APPLICATION")
Set WordReport = GetObject(app.Path + "\NewDoc.doc")
With WordReport.Application
.Visible = True
.Selection.Find.ClearFormatting
.Selection.Find.Text = "Construction"
.Selection.Find.Replacement.Text = "-----------------"
.Selection.Find.Forward = True
.Selection.Find.Execute
........
My problem is, if the user already has a word document openend or, while I'm working in VB with the Word document and the user goes to other editor, the program crashed and say me the error:
**Object variable or with block variable not set**
this error can occurs in any part of the code where I'm using the wordreport object, for example
WordReport.Application.Selection.MoveLeft Unit:=wdCharacter, Count:=1
I was thinking if I need to close all word applications before I start with this, but, I saw, also, if you don't have any Word document opened, this error occurs
any idea??
thanks
I have a VB application and I have a function there, for working with Microsoft Word.
this is the begin the code:
Set WordTemplate = CreateObject("WORD.APPLICATION")
Set WordReport = GetObject(app.Path + "\NewDoc.doc")
With WordReport.Application
.Visible = True
.Selection.Find.ClearFormatting
.Selection.Find.Text = "Construction"
.Selection.Find.Replacement.Text = "-----------------"
.Selection.Find.Forward = True
.Selection.Find.Execute
........
My problem is, if the user already has a word document openend or, while I'm working in VB with the Word document and the user goes to other editor, the program crashed and say me the error:
**Object variable or with block variable not set**
this error can occurs in any part of the code where I'm using the wordreport object, for example
WordReport.Application.Selection.MoveLeft Unit:=wdCharacter, Count:=1
I was thinking if I need to close all word applications before I start with this, but, I saw, also, if you don't have any Word document opened, this error occurs
any idea??
thanks