I need to open a previously created RTF document, make some changes and
then save it back to disk in a different format. Very straightforward
stuff. The following two code snippets look to me as if they ought to
be equivalent, yet the first one fails while the second works fine. I
don't understand why . . . .
EXAMPLE 1 (fails)
Dim WordApp, WordDoc
Err.Clear
Set WordApp = GetObject("Word.Application")
If Err.Num <> 0 Then
Set WordApp = CreateObject("Word.Application")
Err.Clear
End If
intNumCv = WordApp.FileConverters.Count
If Not WordApp Is Nothing 'It always passes this test
WordApp.Options.ConfirmConversions = false
WordApp.Options.DefaultOpenFormat = wdOpenFormatRTF
WordApp.Documents.Open RTFFilename
Set WordDoc = WordApp.ActiveDocument
'
' Alternate format --
' WordDoc = WordApp.Documents.Open( RTFFilename )
'
If Not WordDoc Is Nothing
'
' This condition always evaluates to "false"
' It doesn't seem to matter how I format the
' WordApp.Documents.Open statement -- it will
' always fail
'
End If
End If
EXAMPLE 2 (works)
Dim WordApp, WordDoc
Err.Clear
Set WordDoc = CreateObject( "Word.Document" )
WordDoc.Visible = true
Set WordApp = WordDoc.Application
If WordApp Is Nothing Then
'
' Error handling gympsys in here. Doesn't
' matter -- it's never failed yet.
'
Else
Err.Clear
WordApp.Options.ConfirmConversions = false
WordApp.Options.DefaultOpenFormat = wdOpenFormatRTF
WordApp.Documents.Open RTFFilename
End If
The thing is that the second option (the one that works) is very, very
slow. A new winword.exe process is spawned for each document
conversion. In fact, I have to explicitly call "WordApp.Quit" or we are
quickly buried under winword instances. If I could get the other way to
work, I could create a "WordApp" object with Session_OnStart and then
cache it.
My question is: why isn't it working?
TIA!
--
Ole Yearian
Software Engineer
Convene International
www.convene.com
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.