Results 1 to 31 of 31

Thread: [WORD] Problem to open document

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    [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

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: [WORD] Problem to open document

    Can you post the code used to set the instance of Word and the Variables

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    Re: [WORD] Problem to open document

    VB Code:
    1. okWord = False
    2.     count = 0
    3. '    'on va essayer de lancer 2 fois word en cas d'erreur
    4.     Do While count < 2 And Not okWord
    5.         [COLOR=Red]err.Clear
    6.         Call KillProcessus("winword.exe")
    7.         Set wappliword = New Word.Application
    8.         wappliword.Visible = wordVisible
    9.         'wappliword.DisplayAlerts = wdAlertsNone
    10. [/COLOR]
    11.         'PURGE ALL MSGQ
    12.         Call purgeMsgQ
    13.         'SEND MESSAGE OPEN
    14.         Call sendMsgQ("OPEN")
    15.         'launch appz .NET and try open word
    16.  
    17.         Call Shell("c:\Reader4CleandDoc.exe", vbNormalFocus)
    18.        
    19. [COLOR=Red]        On Error Resume Next
    20.        
    21.         wappliword.Documents.Open cheminAppl
    22.        
    23.         DoEvents[/COLOR]
    24.        
    25.         'on teste s'il y a eu une erreur
    26.         'si la description de l'erreur est vide, c kil ny a pas derreur... lol
    27.         If err.Description = "" Then
    28.             DoEvents
    29.             'read msg
    30.             Call readMsgQ
    31.             'send msg CLOSE 'pour que l'application en .NET s'arrete et qu'il n'attende pas un message
    32.             Call sendMsgQ("CLOSE")
    33.             frmNettoyageDoc.errorOpeningWord = False
    34.             okWord = True
    35.         Else 'sinon on ajoute 1 a count
    36.             count = count + 1
    37.             Call frmWait.getInfo("Retrying #" & count & "# to open doc")
    38.             For i = 1 To 150
    39.                 DoEvents
    40.                 Sleep (100)
    41.                 Call frmWait.Timer1_Timer
    42.             Next i
    43.         End If
    44.     Loop
    Last edited by Dnx_7; Sep 8th, 2005 at 10:35 AM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [WORD] Problem to open document

    Try this:
    Code:
    wappliword.Documents.Open FileName:=cheminAppl

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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...

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [WORD] Problem to open document

    What error does it get?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [WORD] Problem to open document

    I'm not familiar with that error.

    Do you have the routine Error Trapped?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    Re: [WORD] Problem to open document

    what do you mean by routine error trapped? (i don't understand, my english is quite poor, sorry)

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    Re: [WORD] Problem to open document

    oh i see, i have changed all my error handler (trapping like you said )
    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

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [WORD] Problem to open document

    Post your new updated code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    Re: [WORD] Problem to open document

    here is my newest code

    VB Code:
    1. While Not okWord And count < 1000
    2.         count = count + 1
    3.         err.Clear
    4.         Call KillProcessus("winword.exe")
    5.         Set wappliword = New Word.Application
    6.         wappliword.Visible = wordVisible
    7.         wappliword.Application.Visible = wordVisible
    8.         wappliword.DisplayAlerts = wdAlertsNone
    9.         For j = 0 To 50
    10.             Sleep (100)
    11.             DoEvents
    12.         Next j
    13.         On Error Resume Next
    14.         wappliword.Documents.Open nomfichier
    15.         If err.Number = 0 Then
    16.             okWord = True
    17.         Else
    18.             okWord = False
    19.             frmWait.lblInfo.Caption = "Retrying  #" & count & "# to open DOC"
    20.         End If
    21.         DoEvents
    22.         Call frmWait.Timer1_Timer
    23.     Wend

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.
    Last edited by dglienna; Sep 9th, 2005 at 02:56 AM.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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...

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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?

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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.

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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.

  22. #22
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [WORD] Problem to open document

    For your programs EXIT button, substitute this code. It will unload everything that is open.
    VB Code:
    1. Private Sub Command1_Click()
    2.  Dim frm As Form
    3.   Dim obj As Object
    4.   For Each frm In Forms
    5.      If frm.Name <> Me.Name Then ' Unload this form LAST
    6.        For Each obj In frm
    7.          On Error Resume Next
    8.            Unload obj
    9.            Set obj = Nothing
    10.        Next
    11.        Unload frm
    12.        Set frm = Nothing
    13.      End If
    14.     Next
    15.     On Error Resume Next
    16.       For Each obj In frm
    17.         Unload obj
    18.         Set obj = Nothing
    19.       Next
    20.       Set frm = Nothing
    21.       Unload Me
    22. End Sub

  23. #23
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    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
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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

  25. #25
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [WORD] Problem to open document

    Call it when you exit your program. Only ONCE.

  26. #26
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  27. #27
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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

  29. #29
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. While Not okWord And count < 1000
    2.         count = count + 1
    3.         err.Clear
    4.         Call KillProcessus("winword.exe")
    5.         Set wappliword = New Word.Application
    6.         wappliword.Visible = wordVisible
    7.         wappliword.Application.Visible = wordVisible
    8.         wappliword.DisplayAlerts = wdAlertsNone
    9.         For j = 0 To 50
    10.             Sleep (100)
    11.             DoEvents
    12.         Next j
    13.         On Error Resume Next
    14.         wappliword.Documents.Open nomfichier
    15.         If err.Number = 0 Then
    16.             okWord = True
    17.         Else
    18.             okWord = False
    19.             frmWait.lblInfo.Caption = "Retrying  #" & count & "# to open DOC"
    20.         End If
    21.         DoEvents
    22.         Call frmWait.Timer1_Timer
    23.     Wend
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  30. #30

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Location
    Charleroi (Belgium)
    Posts
    18

    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"

  31. #31
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. On Error Resume Next
    2. wappliword.Documents.Open nomfichier
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width