|
-
Aug 18th, 2005, 10:59 AM
#1
Thread Starter
Member
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.
-
Aug 18th, 2005, 12:45 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 18th, 2005, 01:04 PM
#3
Thread Starter
Member
Re: MS Word Events
Even if i catch the document close event ..still its never executed.
adhi
-
Aug 18th, 2005, 02:13 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 18th, 2005, 02:58 PM
#5
Thread Starter
Member
Re: MS Word Events
-
Aug 22nd, 2005, 07:15 AM
#6
Thread Starter
Member
Re: MS Word Events
Rob,
Can you explain how to do, what you have mentioned in your last reply.
adhi
-
Aug 22nd, 2005, 08:56 AM
#7
Thread Starter
Member
Re: MS Word Events
Could somebody please help me with this.
-
Aug 22nd, 2005, 10:43 AM
#8
Thread Starter
Member
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
-
Aug 22nd, 2005, 06:12 PM
#9
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:
Option Explicit
'Add a reference to MS Word xx.0 Object Library
'Add 3 command buttons to your form
Private moApp As Word.Application
Private moDoc As Word.Document
Private WithEvents myAppEvt As Word.Application
Private WithEvents myDocEvt As Word.Document
Private Sub Command1_Click()
'Add a new document and initialize/link the document event
moApp.Visible = True
Set moDoc = moApp.Documents.Add
Set myDocEvt = moDoc
End Sub
Private Sub Command2_Click()
'Close the document
moDoc.Close False
End Sub
Private Sub Command3_Click()
'Quit the word application
moApp.Quit False
End Sub
Private Sub Form_Load()
'Create the application and initialize application event
Set moApp = New Word.Application
Set myAppEvt = Word.Application
End Sub
Private Sub myAppEvt_Quit()
'Detect the word quit event
MsgBox "Quit"
End Sub
Private Sub myDocEvt_Close()
'detect the document close event
MsgBox "Close"
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 23rd, 2005, 01:58 PM
#10
Thread Starter
Member
-
Aug 23rd, 2005, 02:05 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 23rd, 2005, 02:07 PM
#12
Thread Starter
Member
Re: MS Word Events[Resolved]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|