Solved

Word document and its Open/Closed status controlled via VB6

Posted on 2011-03-17
3
326 Views
Last Modified: 2012-05-11
This is the code lines that work to open the word document.  
    Set objWordApp = CreateObject("Word.Application")
    Set objWordDoc = CreateObject("Word.Document")
   
    Set objWordDoc = objWordApp.Documents.Open(strMailMergeFilePath)
    objWordApp.Visible = True

After this lines I have the document opened and user can view it.  I would like to application to do some other stuff when user clicked the word document "closed' - that x - button in the right upper corner.

Is this possible to do?  Can the application see the status of the objWordDoc?

I
0
Comment
Question by:Aquarus
3 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35163944
>>> Can the application see the status of the objWordDoc?

In your code trap errors. That should let you know if the user manually closes the word document.

Sid
0
 
LVL 3

Accepted Solution

by:
greisch earned 500 total points
ID: 35178921
Create a class CWordDocument that can handle the document events :

Option Explicit

Public WithEvents Doc As Word.Document

'You can add properties and methods as you want'

Private Sub Doc_Close()
  ' Do what you want to be done when the doc is closed'
End Sub

Open in new window


Then in your code do :

Dim wordDoc as New CWordDocument
Set wordDoc.Doc = objWordApp.Documents.Open(strMailMergeFilePath)
objWordApp.Visible = True

Open in new window


When the document is closed by the user, Doc_Close in CWordDocument is called.
0
 

Author Comment

by:Aquarus
ID: 35183524
Thank you ,

I am almost done here.

Can I programmatically set up the property of the word document so when the user closes it the word application does warn: Save or No or Cancel?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 68
String manipulation in Visual Basic 7 64
MsgBox 2 56
I need help embedding an image as HTML in my vb.net application 3 69
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question