How to catch the window close event in VB6? 
Author Message
 How to catch the window close event in VB6?

Hi,

I am writing a VB6 app, which can launch a couple different types of files,
such as Word, Excel, PDF. These files are created on the fly when user clicks
the VB6 app to open them.
Here is the code segment that I used to do this:

      Set appWord = New Word.Application
      Set docWord = New Word.Document
      appWord.Visible = True
      Set docWord = appWord.Documents.Open(sFullFileName, , False, False, ,
, True)
      docWord.Activate

Therefore I want to prompt the user before he closes the files whether he
wants to save them or not. If user does not want to save, I want to delete
these files, otherwise I will prompt the user where he wants to save it. This
is where I got stuck. I have searched quite a while on the internet to look
for the window closing event for VB6, but it seems there is no such thing.
Any idea I can handel this situation? Thanks!!

By the way, these files are independent of each other, user can open them in
any order he likes, so can he close them in any order he likes.



Sun, 29 Jan 2012 06:18:01 GMT  
 How to catch the window close event in VB6?


Quote:
> Hi,

> I am writing a VB6 app, which can launch a couple different types of files,
> such as Word, Excel, PDF. These files are created on the fly when user clicks
> the VB6 app to open them.
> Here is the code segment that I used to do this:

> ? ? ? Set appWord = New Word.Application
> ? ? ? Set docWord = New Word.Document
> ? ? ? appWord.Visible = True
> ? ? ? Set docWord = appWord.Documents.Open(sFullFileName, , False, False, ,
> , True)
> ? ? ? docWord.Activate

> Therefore I want to prompt the user before he closes the files whether he
> wants to save them or not. If user does not want to save, I want to delete
> these files, otherwise I will prompt the user where he wants to save it. This
> is where I got stuck. I have searched quite a while on the internet to look
> for the window closing event for VB6, but it seems there is no such thing.
> Any idea I can handel this situation? Thanks!!

> By the way, these files are independent of each other, user can open them in
> any order he likes, so can he close them in any order he likes.

For Word documents check out the Document_Close event.
Also check out the Document.Saved property to know whether or not the
document needs saved.

For Excel check out the Workbook_BeforeClose event.  The workbook
object also has a Saved property.

To use either of these will require that you declare your Document
(for Word) and Workbook object (for Excel) WithEvents

Hope this helps,
Steve



Sun, 29 Jan 2012 06:52:46 GMT  
 How to catch the window close event in VB6?
Thanks, Steve. That works perfect!
Quote:



> > Hi,

> > I am writing a VB6 app, which can launch a couple different types of files,
> > such as Word, Excel, PDF. These files are created on the fly when user clicks
> > the VB6 app to open them.
> > Here is the code segment that I used to do this:

> >       Set appWord = New Word.Application
> >       Set docWord = New Word.Document
> >       appWord.Visible = True
> >       Set docWord = appWord.Documents.Open(sFullFileName, , False, False, ,
> > , True)
> >       docWord.Activate

> > Therefore I want to prompt the user before he closes the files whether he
> > wants to save them or not. If user does not want to save, I want to delete
> > these files, otherwise I will prompt the user where he wants to save it. This
> > is where I got stuck. I have searched quite a while on the internet to look
> > for the window closing event for VB6, but it seems there is no such thing..
> > Any idea I can handel this situation? Thanks!!

> > By the way, these files are independent of each other, user can open them in
> > any order he likes, so can he close them in any order he likes.

> For Word documents check out the Document_Close event.
> Also check out the Document.Saved property to know whether or not the
> document needs saved.

> For Excel check out the Workbook_BeforeClose event.  The workbook
> object also has a Saved property.

> To use either of these will require that you declare your Document
> (for Word) and Workbook object (for Excel) WithEvents

> Hope this helps,
> Steve



Sun, 29 Jan 2012 07:34:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to catch events for window minimize,close

2. How to catch the close window event

3. CTD 2.1 ActiveX Container doesn't catch the second UserControl_KeyDown vb6 Event

4. CTD 2.1 ActiveX Container doesn't catch the second UserControl_KeyDown vb6 Event

5. Catching frame events from VB6 program

6. closing the Yes/No window when closing a Shelled Window

7. Problems Closing a New Window using window.close()

8. Closing Parent Window when the child window closes

9. Best way to make VB6 app aware of Word 97 document close event

10. Visual Basic - Trapping Minimize/Maximize/Close Events (from the window's buttons)

11. capturing the Window close event in Excel

12. close window mouse event

 

 
Powered by phpBB® Forum Software