-
[WORD] Problem to open document
Hi, i control Word with VB6
and i when i try this command
"myWord.Documents.Open FilePath"
filePath contain the full path of the document to open.
the problem is when he try to open the document, he get an error
"Word n'a pas pu appliquer l'événement"
in english :
" Word could not apply the event "
i don't know why because if i open the doc manually, it works :(
best regards
-
Re: [WORD] Problem to open document
Can you post the code used to set the instance of Word and the Variables :)
-
Re: [WORD] Problem to open document
VB Code:
okWord = False
count = 0
' 'on va essayer de lancer 2 fois word en cas d'erreur
Do While count < 2 And Not okWord
[COLOR=Red]err.Clear
Call KillProcessus("winword.exe")
Set wappliword = New Word.Application
wappliword.Visible = wordVisible
'wappliword.DisplayAlerts = wdAlertsNone
[/COLOR]
'PURGE ALL MSGQ
Call purgeMsgQ
'SEND MESSAGE OPEN
Call sendMsgQ("OPEN")
'launch appz .NET and try open word
Call Shell("c:\Reader4CleandDoc.exe", vbNormalFocus)
[COLOR=Red] On Error Resume Next
wappliword.Documents.Open cheminAppl
DoEvents[/COLOR]
'on teste s'il y a eu une erreur
'si la description de l'erreur est vide, c kil ny a pas derreur... lol
If err.Description = "" Then
DoEvents
'read msg
Call readMsgQ
'send msg CLOSE 'pour que l'application en .NET s'arrete et qu'il n'attende pas un message
Call sendMsgQ("CLOSE")
frmNettoyageDoc.errorOpeningWord = False
okWord = True
Else 'sinon on ajoute 1 a count
count = count + 1
Call frmWait.getInfo("Retrying #" & count & "# to open doc")
For i = 1 To 150
DoEvents
Sleep (100)
Call frmWait.Timer1_Timer
Next i
End If
Loop
-
Re: [WORD] Problem to open document
Try this:
Code:
wappliword.Documents.Open FileName:=cheminAppl
-
Re: [WORD] Problem to open document
i already tried this command
i have put this command line into a while instruction
and while it get an error, it loops
now it works with this tricks, i don't know why...
-
Re: [WORD] Problem to open document
-
Re: [WORD] Problem to open document
always the same problem, sometimes, after 50 tests it can work and sometimes after 100 tests it passes... it is very random...
the error is : "word ne peut appliquer cet événement"
in english i think is "word cannot apply this event"
best regards
-
Re: [WORD] Problem to open document
I'm not familiar with that error.
Do you have the routine Error Trapped?
-
Re: [WORD] Problem to open document
what do you mean by routine error trapped? (i don't understand, my english is quite poor, sorry)
-
Re: [WORD] Problem to open document
In the word document to be opened, do you have any code behind it?
For error trapping Hack is referring to an "On Error GoTo ErrorSub" at the top of your procedure. I see the If Err.Description = "" but that should be checking the Err.Number <> 0 for an error because there may be an description without any text so the error would fall through causing a problem. ;)
-
Re: [WORD] Problem to open document
Error Trapping has the benefit of preventing (generally speaking) run time errors that will blow your uses back to the desktop and stop the execution of your program. All of your code routines should be error trapped before you roll your code out.
-
Re: [WORD] Problem to open document
oh i see, i have changed all my error handler (trapping like you said :p)
and it doesn't work too
it is a very simple file *.RTF and there are only text inside
i really don't understand...
best regards
-
Re: [WORD] Problem to open document
Post your new updated code. ;)
-
Re: [WORD] Problem to open document
here is my newest code :p
VB Code:
While Not okWord And count < 1000
count = count + 1
err.Clear
Call KillProcessus("winword.exe")
Set wappliword = New Word.Application
wappliword.Visible = wordVisible
wappliword.Application.Visible = wordVisible
wappliword.DisplayAlerts = wdAlertsNone
For j = 0 To 50
Sleep (100)
DoEvents
Next j
On Error Resume Next
wappliword.Documents.Open nomfichier
If err.Number = 0 Then
okWord = True
Else
okWord = False
frmWait.lblInfo.Caption = "Retrying #" & count & "# to open DOC"
End If
DoEvents
Call frmWait.Timer1_Timer
Wend
-
Re: [WORD] Problem to open document
Quote:
Originally Posted by hack
"blow your uses back to the desktop"
That is the best line that I've heard all night. :thumb:
-
Re: [WORD] Problem to open document
i have tested my program on my laptop and it works better, files are opening faster and it get less error!
i don't know why because i have the same office suite 2003...
-
Re: [WORD] Problem to open document
now the error message is :
"not enough memorry, please save your document and save it"
can somebody can help me?
-
Re: [WORD] Problem to open document
You are running out of memory because you are setting objects, and not resetting them to nothing when you are done. If you press Control-Alt-Delete, and look in the Processes tab, you will find a few instances (maybe many) of WORD. You can manually end the processes, or you can code you project to close them properly. Take a look in the Office forum
-
Re: [WORD] Problem to open document
no it's not that, i'm sure of it coz i always look at the running processes and if you look closely my code, you will see that i "end process" of word each time before open word again.
-
Re: [WORD] Problem to open document
Set a breakpoint, and begin stepping through your code. With any luck, you will be able to see where the loop is occurring that eats up all your memory. I had it when I was setting the click event in a checkbox. didn't think selecting the checkbox as vbUnchecked would mess things up, but each time the click event fired, but code to set it fired.
It ran for about 2 minutes, and then crashed, and wouldn't let me do anything with my system. Totally out of memory. I had to reboot, before I could start debugging.
-
Re: [WORD] Problem to open document
hmm i see, it is possibble, i'm agree but my application works perfectly on my laptop? why not on my desktop computer???
i already have tried to see where it bugs and it is when the application try to open the document.
-
Re: [WORD] Problem to open document
For your programs EXIT button, substitute this code. It will unload everything that is open.
VB Code:
Private Sub Command1_Click()
Dim frm As Form
Dim obj As Object
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
For Each obj In frm
On Error Resume Next
Unload obj
Set obj = Nothing
Next
Unload frm
Set frm = Nothing
End If
Next
On Error Resume Next
For Each obj In frm
Unload obj
Set obj = Nothing
Next
Set frm = Nothing
Unload Me
End Sub
-
Re: [WORD] Problem to open document
I suspect you are using Getobject to open instances of word this would be the fundamental cause of your problem. if so use this:
Code:
on error resume next
getobject("Word.Application")
if Err then
creatobject("Word.Application")
end if
on error goto ..... 'to your normal error handler
instead, it
will prevent opening so many instances of word in the first place. leaving memory for other proccesses
-
Re: [WORD] Problem to open document
i see, but my instance of word is in a module, i don't know how to unload all the object in the module :(
-
Re: [WORD] Problem to open document
Call it when you exit your program. Only ONCE.
-
Re: [WORD] Problem to open document
Quote:
Originally Posted by dglienna
Call it when you exit your program. Only ONCE.
And the place to call it from when you exit your program is the Unload event of your main form.
-
Re: [WORD] Problem to open document
Your problem comes from creating and destroying Word over and aover again. You do not need to do that. Create one instance of Word, open a document, do something, close the document and then open another. You can not say that just because it works on your laptop and not your desktop that there is nothing wrong with your code. If someone else uses it it will perform even different. ;)
-
Re: [WORD] Problem to open document
i'm agree with you when you say "open and destroy word over and over again" => yes it s not very clean... but explain me why for the FIRST instance of word and the FIRST instruction to open a document with word CRASH the application and get error???
and it is an error of memory :(
-
Re: [WORD] Problem to open document
If this is your current code then and its crashing on "Set wappliword = New Word.Application" then it could either be that your object variable is not defined as a Word.Application or it may be crashing on your KillProcesses("winword.exe").
VB Code:
While Not okWord And count < 1000
count = count + 1
err.Clear
Call KillProcessus("winword.exe")
Set wappliword = New Word.Application
wappliword.Visible = wordVisible
wappliword.Application.Visible = wordVisible
wappliword.DisplayAlerts = wdAlertsNone
For j = 0 To 50
Sleep (100)
DoEvents
Next j
On Error Resume Next
wappliword.Documents.Open nomfichier
If err.Number = 0 Then
okWord = True
Else
okWord = False
frmWait.lblInfo.Caption = "Retrying #" & count & "# to open DOC"
End If
DoEvents
Call frmWait.Timer1_Timer
Wend
-
Re: [WORD] Problem to open document
no it doesn't crash at the line "set wappliword..." i meant that it crash when it makes for the first time an instance of word but the crash is on the line where it try to open the doculment
"wappliword.documents.open nomfichier"
-
Re: [WORD] Problem to open document
But you have the resume next error statement. That is not helping you determine what is the actual error. Take it out and step through the code and see what the real error message is. ;)
VB Code:
On Error Resume Next
wappliword.Documents.Open nomfichier