Results 1 to 12 of 12

Thread: MS Word Events[Resolved]

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Resolved MS Word Events[Resolved]

    Hi,
    I have a VB application that creates a Word(set win =new word.application) object and add document to it. Finally after add all the documents to the master document it saves the master file and makes the document visible to the user.After reviewing the created document when the user closes the document i want to do some operations.
    for this is delcared varialbe win withEvents
    Dim WithEvents win as Word.Applicaition

    And in the procedure private sub win_quit() i coded the operations that i want to perform.

    But when the user closes word the control never comes to win_quit() and the operation in the procedure is never executed. Please let me know what should i do.

    Thanks
    Adhi
    Last edited by adhavanv; Aug 23rd, 2005 at 01:58 PM.

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

    Re: MS Word Events

    You catching the application closing event and not the document closing event.
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word Events

    Even if i catch the document close event ..still its never executed.

    adhi

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

    Re: MS Word Events

    Are you setting your doc event object in the app open event? You need both so when the app is opened it can set the doc event of the doc thats opening. They need to be linked together or it doesnt know which instance to link.
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Question Re: MS Word Events

    No how to do that????

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word Events

    Rob,
    Can you explain how to do, what you have mentioned in your last reply.

    adhi

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word Events

    Could somebody please help me with this.

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word Events

    Rob
    Do you mean to say that i have to register the class in the ThisDocument to connect the class and its events to word application??

    adhi

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

    Re: MS Word Events

    Here is a small and quick example I wrote for you to show how to link the app events and the document events.
    VB Code:
    1. Option Explicit
    2. 'Add a reference to MS Word xx.0 Object Library
    3. 'Add 3 command buttons to your form
    4. Private moApp As Word.Application
    5. Private moDoc As Word.Document
    6.  
    7. Private WithEvents myAppEvt As Word.Application
    8. Private WithEvents myDocEvt As Word.Document
    9.  
    10. Private Sub Command1_Click()
    11.     'Add a new document and initialize/link the document event
    12.     moApp.Visible = True
    13.     Set moDoc = moApp.Documents.Add
    14.     Set myDocEvt = moDoc
    15. End Sub
    16.  
    17. Private Sub Command2_Click()
    18.     'Close the document
    19.     moDoc.Close False
    20. End Sub
    21.  
    22. Private Sub Command3_Click()
    23.     'Quit the word application
    24.     moApp.Quit False
    25. End Sub
    26.  
    27. Private Sub Form_Load()
    28.     'Create the application and initialize application event
    29.     Set moApp = New Word.Application
    30.     Set myAppEvt = Word.Application
    31. End Sub
    32.  
    33. Private Sub myAppEvt_Quit()
    34.     'Detect the word quit event
    35.     MsgBox "Quit"
    36. End Sub
    37.  
    38. Private Sub myDocEvt_Close()
    39.     'detect the document close event
    40.     MsgBox "Close"
    41. End Sub
    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

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word Events

    That was perfect.

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

    Re: MS Word Events[Resolved]

    Thanks! Sorry for the delay in posting the code example. Things have been quite hecktic lately for me.
    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

  12. #12

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    40

    Re: MS Word Events[Resolved]

    Not a problem

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