M
Mike Moschella
I am having a problem with opening word application from
vb doing a word merge and then closing the word
application. My problem is that after word is quit, it
does not return to the vb form that opened it. So if I
have a window open to a directory of my hard disk or
another application and start my application and open word
and do a mail merge and then close word it jumps to the
open directory window or application window, also this
only happens in a complied code.
I think the problem maybe related to my structure of the
applicaion. I have an vb .exe that has a main form that
uses .ocx control that opens a modal form that opens word.
I tried making a simple .exe with a form that opens word
and it returned correctly, which makes me think there is
a problem with my structure.
Below is some code I tested in my Application and in my
test .exe. Is there some way I can tell word to go back
to the modal dialog form that called it. Or do I need to
change something in the modal form. Or is it because I
have an .exe that has a form that uses a control from
an .ocx that calls an modal dialog which opens word.
Thanks
Mike
Set mWrd = CreateObject("Word.Application")
Set mDoc = mWrd.Documents.Open
("C:\MailMerge\AppReturn\temp\TempTemplate.doc")
Set mTempDoc = mWrd.ActiveDocument
mDoc.MailMerge.MainDocumentType = wdFormLetters
mDoc.MailMerge.OpenDataSource
Name:="C:\MailMerge\AppReturn\temp\data2.dat"
mWrd.Visible = True
mWrd.Activate
Screen.MousePointer = vbDefault
mDoc.MailMerge.Destination = wdSendToNewDocument
mDoc.MailMerge.Execute
Set mMergeDoc = mWrd.ActiveDocument
mMergeDoc.Activate '.Documents("Form Letters1").Activate
mMergeDoc.PrintOut
mMergeDoc.Saved = True
mMergeDoc.Close
mDoc.MailMerge.MainDocumentType =
wdNotAMergeDocument 'releases template data so itcan be
deleted
Set mMergeDoc = Nothing
mDoc.Saved = True
mDoc.Close
Set mTempDoc = Nothing
mWrd.Application.Quit False
Set mWrd = Nothing
vb doing a word merge and then closing the word
application. My problem is that after word is quit, it
does not return to the vb form that opened it. So if I
have a window open to a directory of my hard disk or
another application and start my application and open word
and do a mail merge and then close word it jumps to the
open directory window or application window, also this
only happens in a complied code.
I think the problem maybe related to my structure of the
applicaion. I have an vb .exe that has a main form that
uses .ocx control that opens a modal form that opens word.
I tried making a simple .exe with a form that opens word
and it returned correctly, which makes me think there is
a problem with my structure.
Below is some code I tested in my Application and in my
test .exe. Is there some way I can tell word to go back
to the modal dialog form that called it. Or do I need to
change something in the modal form. Or is it because I
have an .exe that has a form that uses a control from
an .ocx that calls an modal dialog which opens word.
Thanks
Mike
Set mWrd = CreateObject("Word.Application")
Set mDoc = mWrd.Documents.Open
("C:\MailMerge\AppReturn\temp\TempTemplate.doc")
Set mTempDoc = mWrd.ActiveDocument
mDoc.MailMerge.MainDocumentType = wdFormLetters
mDoc.MailMerge.OpenDataSource
Name:="C:\MailMerge\AppReturn\temp\data2.dat"
mWrd.Visible = True
mWrd.Activate
Screen.MousePointer = vbDefault
mDoc.MailMerge.Destination = wdSendToNewDocument
mDoc.MailMerge.Execute
Set mMergeDoc = mWrd.ActiveDocument
mMergeDoc.Activate '.Documents("Form Letters1").Activate
mMergeDoc.PrintOut
mMergeDoc.Saved = True
mMergeDoc.Close
mDoc.MailMerge.MainDocumentType =
wdNotAMergeDocument 'releases template data so itcan be
deleted
Set mMergeDoc = Nothing
mDoc.Saved = True
mDoc.Close
Set mTempDoc = Nothing
mWrd.Application.Quit False
Set mWrd = Nothing