Hoping someone can point me in a direction--tearing my hair out! (and I don't have much!)
My users can call a function to import specific word file's text into a shapes textbox. Works fine.
But, after each call, they have a "Microsoft Word (32 bit) process running in the Windows task manager--even though I "try" to close and quit the word app I started. They can end up with dozens or hundreds--one for each import operation they've called.
Worse--if they force quit all the processes--the next call to import a doc will usually fail (doesn't give an error--just... doesn't happen). In fact, I have to remove the "docApp.Quit" line shown below as it does the same thing--with it in place they get one good import, then... nothing!
Is there some better, more reliable way to deal with these Word operations that doesn't leave orphaned processes? Here's the stripped down code I'm using to do the imports...
My users can call a function to import specific word file's text into a shapes textbox. Works fine.
But, after each call, they have a "Microsoft Word (32 bit) process running in the Windows task manager--even though I "try" to close and quit the word app I started. They can end up with dozens or hundreds--one for each import operation they've called.
Worse--if they force quit all the processes--the next call to import a doc will usually fail (doesn't give an error--just... doesn't happen). In fact, I have to remove the "docApp.Quit" line shown below as it does the same thing--with it in place they get one good import, then... nothing!
Is there some better, more reliable way to deal with these Word operations that doesn't leave orphaned processes? Here's the stripped down code I'm using to do the imports...
VBA Code:
Function ImportWordDoc()
Dim docApp As Object
Dim docMyDoc As Object
Dim Doc_to_import As String
Set docApp = CreateObject("Word.Application")
Set docMyDoc = CreateObject("Word.document")
Set docMyDoc = Documents.Open("my_word_file.docx", Visible = True)
' Get our Word data (grabbing all of it) into the clipboard then set our textbox to the clipboard contents
With docMyDoc
.Range(Start:=0, End:=.Characters.count).Copy
Ticket_sheet.Shapes("Textbox_1").TextFrame.Characters.Text = Clipboard
End With
' Close the Word doc, get rid of objects...
docMyDoc.Close
docApp.Quit '<------ I can't leave this in, it makes the next import fail
Set docMyDoc = Nothing
Set docApp = Nothing
End Function