radshaw_longer
asked on
In VB.Net how to check for to see if Word is already running and if so, open new document without opening new instance of Word
I'm very new to VB.Net but I'm asking the users to fill out a form i.e. name, address, etc. than pass that information into a word file placing the data from vb.net into word using bookmarks. My program is running fine, but it keeps opening a new instance of Word everytime. I would like to check to see if Word is open and then just open that document as well. Here is my current code, any help would be greatly appreciated. Thanks
If rbGiftReturn.Checked = True Then
Dim BM As Word.Bookmark
myWord = CreateObject("Word.applica tion")
With myWord
.Documents.Open("C:\engage ment letter\templates\gift tax return.doc")
.ActiveDocument.Bookmarks. Item("bmSa lutation") .Range.Tex t = cbSalutation.Text
.ActiveDocument.Bookmarks. Item("bmCo ntact").Ra nge.Text = txtContact.Text
.ActiveDocument.Bookmarks. Item("bmCo mpany").Ra nge.Text = txtCompany.Text
.ActiveDocument.Bookmarks. Item("bmSt reet").Ran ge.Text = txtStreet.Text
.ActiveDocument.Bookmarks. Item("bmCi ty").Range .Text = txtCity.Text
.ActiveDocument.Bookmarks. Item("bmSt ate").Rang e.Text = txtState.Text
.ActiveDocument.Bookmarks. Item("bmZi p").Range. Text = txtZIP.Text
.ActiveDocument.Bookmarks. Item("bmCo ntact1").R ange.Text = txtContact.Text
.ActiveDocument.Bookmarks. Item("bmMo nth").Rang e.Text = cbYearEnd.Text
.ActiveDocument.Bookmarks. Item("bmYe ar").Range .Text = cbTaxYear.Text
.ActiveDocument.Bookmarks. Item("bmPr eparer").R ange.Text = cbPreparer.Text
.ActiveDocument.Bookmarks. Item("bmEn tities").R ange.Text = clbEntities.Text
.ActiveDocument.Bookmarks. Item("bmSa lutation1" ).Range.Te xt = cbSalutation.Text
.ActiveDocument.Bookmarks. Item("bmCo ntact2").R ange.Text = txtContact.Text
.Visible = True
.Activate()
End With
'myDoc = Nothing
myWord = Nothing
GC.Collect()
End If
Thanks again
If rbGiftReturn.Checked = True Then
Dim BM As Word.Bookmark
myWord = CreateObject("Word.applica
With myWord
.Documents.Open("C:\engage
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.ActiveDocument.Bookmarks.
.Visible = True
.Activate()
End With
'myDoc = Nothing
myWord = Nothing
GC.Collect()
End If
Thanks again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.