Cindy
Mon Aug 23 12:10:33 CDT 2004
Hi Msnews,
First, let's make sure the document can be opened at all? Can you open the
document in Word by hand? Do you get any kind of message?
Then, comment out all the other lines, just to make sure the problem is
occurring on only the one line. Also, remove everything except the first
argument (the file path) from the Open method.
Also, I see you neither display the Word application, nor explicitly close it
at the end. If you do this, Word will remain in memory (look in the Task
Manager). Perhaps you ran some code creating a new Word Application a few
times, and that's why you're suddenly getting messages about being out of
memory?
Just sort of "by the way": the code you're using is considered very poor as it
doesn't use the Word object model, but relies on doing things as the user
would. That's inefficient and generally inaccurate. This would be better:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim WordApp As New Word.ApplicationClass
Dim doc as Word.Document
Dim contentsofword As String
'So that you can see messages and such during testing
WordApp.Visible = True
doc = WordApp.Documents.Open("C:\temp\worddocs\1.doc")
contentsOfWord = doc.Range.Text
doc.Close(wdDoNotSaveChanges)
'Note that at this point, the Word application
'is still loaded in memory!!! You must release it
'explicitly!!!
'WordApp.Quit
End Sub
> I'm having problems using the word.applicationclass to load a word document.
> I've created this very simple code and I get the error below on the
> WordApp.Documents.Open("C:\temp\worddocs\1.doc", 0, 1) line.
>
> An unhandled exception of type 'System.Runtime.InteropServices.COMException'
> occurred in test.exe
> Additional information: There is insufficient memory. Save the document now.
>
> This is my full code!
> Please help, this is getting annoying.
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
> Dim WordApp As New Word.ApplicationClass
>
> Dim contentsofword As String
>
> WordApp.Documents.Open("C:\temp\worddocs\1.doc", 0, 1)
>
> WordApp.Selection.WholeStory()
>
> contentsofword = WordApp.Selection.Text
>
> WordApp.ActiveDocument.Close()
>
> End Sub
>
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)