Solved

Word document and its Open/Closed status controlled via VB6

Posted on 2011-03-17
3
327 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 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