Jeepers321
Technical User
I have a button on an outlook form that takes the data from that form and sends it to a word document with strategically placed bookmarks for that data.
My problem is this.
When the user clicks this button, everything works fine, but when they close the document or if they close MSWord the document is still open in the memory. I had a user this morning tell me that when she opened word she got 8 recovery documents that also opened and they all pretained to documents this form created the day before.
Please look at my code below and offer any suggestion you may have. I thought I was killing everything I "Set" but there is something there that just won't DIE.
Thanks.
Sub OLBtn_Click()
Dim strTemplate
Dim objWord
Dim objDocs
Dim mybklist
Dim CustRefNum
Set objWord = CreateObject("Word.Application"
' Put the name of your Word template that contains the bookmarks
strTemplate = "MyWordTemplate.dot"
' Location of Word template; could be on a shared LAN
strTemplate = "\\Network Folder\Template Folder\" & strTemplate
Set objDocs = objWord.Documents
objDocs.Add strTemplate
set mybklist = objWord.ActiveDocument.Bookmarks
' Bookmark CustRefNum
objWord.ActiveDocument.Bookmarks("CustRefNum"
.Select 'Name of the Document Bookmark
CustRefNum = Item.UserProperties.find("Customer Ref"
.Value 'Name of the Outlook Field
If CustRefNum = True then
CustRefNum = "Yes"
ElseIf CustRefNum = False then
CustRefNum = ""
End If
objWord.Selection.TypeText Cstr(CustRefNum)
objWord.visible = True
Set strTemplate = Nothing
Set ObjWord = Nothing
Set ObjDocs = Nothing
Set mybklist = Nothing
Set CustRefNum = Nothing
End Sub
My problem is this.
When the user clicks this button, everything works fine, but when they close the document or if they close MSWord the document is still open in the memory. I had a user this morning tell me that when she opened word she got 8 recovery documents that also opened and they all pretained to documents this form created the day before.
Please look at my code below and offer any suggestion you may have. I thought I was killing everything I "Set" but there is something there that just won't DIE.
Thanks.
Sub OLBtn_Click()
Dim strTemplate
Dim objWord
Dim objDocs
Dim mybklist
Dim CustRefNum
Set objWord = CreateObject("Word.Application"
' Put the name of your Word template that contains the bookmarks
strTemplate = "MyWordTemplate.dot"
' Location of Word template; could be on a shared LAN
strTemplate = "\\Network Folder\Template Folder\" & strTemplate
Set objDocs = objWord.Documents
objDocs.Add strTemplate
set mybklist = objWord.ActiveDocument.Bookmarks
' Bookmark CustRefNum
objWord.ActiveDocument.Bookmarks("CustRefNum"
CustRefNum = Item.UserProperties.find("Customer Ref"
If CustRefNum = True then
CustRefNum = "Yes"
ElseIf CustRefNum = False then
CustRefNum = ""
End If
objWord.Selection.TypeText Cstr(CustRefNum)
objWord.visible = True
Set strTemplate = Nothing
Set ObjWord = Nothing
Set ObjDocs = Nothing
Set mybklist = Nothing
Set CustRefNum = Nothing
End Sub