Discussion:
Word as E-mail Editor issues
(too old to reply)
McKilty
2009-10-12 12:16:25 UTC
Permalink
I have a routine which opens Word and writes e-mails to it. When it
closes, I get an error regarding the default template and how it can't
be overwritten because it's in use. This is caused, in part, by using
Word as the e-mail editor.

Prior to running the program, if I manually check my Windows processes
for WINWORD.exe, there is one there already caused by Outlook using
Word as an editor. If I close it and then run my app there is no
problem.

The template being references is Normal.dot and I try to use a
different template right off the bat to get around this.

If I don't close it, I get the error. The Word code within my Outlook
macro is:

*******************************************************
Dim myWord As Word.Application
Dim myDoc As Word.Document
Dim sWordString As String

Set myWord = New Word.Application
Set myDoc = myWord.Documents.Add("C:\Program Files\DLB\DailySRE
\FolderExport.dot")

sWordFile = "C:\" & myOutlook.ActiveExplorer.CurrentFolder.Name &
".doc"
myDoc.SaveAs sWordFile

~ SNIP ~

myDoc.Save
myDoc.Close

myWord.Quit

Set myDoc = Nothing
Set myWord = Nothing
**************************************************

This may be the wrong forum, but it is being run in Outlook VBA...
McKilty
2009-10-12 12:46:31 UTC
Permalink
I came up with a solution... it's not the best solution, but it
works. I'm hoping someone comes up with something better.

I've added error handling around the code to open Word

On Error GoTo ErrorHandler
Set myWord = Word.Application
On Error GoTo 0


If I get error 462, then my errorhandler runs this:

Set myWord = New Word.Application

and then resumes to the next line.


Like I said, it's not great...
Ken Slovak - [MVP - Outlook]
2009-10-12 13:45:30 UTC
Permalink
Look at GetObject(), used to get an instance of a running application.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by McKilty
I came up with a solution... it's not the best solution, but it
works. I'm hoping someone comes up with something better.
I've added error handling around the code to open Word
On Error GoTo ErrorHandler
Set myWord = Word.Application
On Error GoTo 0
Set myWord = New Word.Application
and then resumes to the next line.
Like I said, it's not great...
McKilty
2009-10-12 14:36:49 UTC
Permalink
Thanks.

I'm not sure if this is the best solution either, but it works better
than what I was doing.


On Error Resume Next
Set myWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set myWord = New Word.Application
End If
On Error GoTo 0
Ken Slovak - [MVP - Outlook]
2009-10-12 20:30:02 UTC
Permalink
On Error Resume Next
blnWeCreated = False
Set myWord = GetObject(, "Word.Application")
If myWord Is Nothing Then
blnWeCreated = True
Set myWord = New Word.Application
End If

That way you know if you want to shut it down when finished.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by McKilty
Thanks.
I'm not sure if this is the best solution either, but it works better
than what I was doing.
On Error Resume Next
Set myWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set myWord = New Word.Application
End If
On Error GoTo 0
Loading...