Solved

Word document and its Open/Closed status controlled via VB6

Posted on 2011-03-17
3
324 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
Comment Utility
>>> 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now