Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with Calling a subroutine in the ThisWorkbook Class

Hi All,

I have defined a subroutine in the ThisWorkbook class as:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

--- code

--- code

End Sub


Now I have another subroutine in Module 1 of my workbook:


Sub Userform()

-- Code

-- Code



If Err = 0

Then Call Workbook_BeforeClose(True)
Exit Sub
End If

End Sub


Now I want to call the subroutine Workbook_BeforeClose from within the
Userform() routine, if there is an Error is encountered -- basically i
want to close the entire workbook.

Can somebody shed light on how to achieve this ?

Thanks,
Ravi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Help with Calling a subroutine in the ThisWorkbook Class


Instead of... Call Workbook_BeforeClose(True)
Use... ThisWorkbook.Close
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"freshforlife"
wrote in message
Hi All,
I have defined a subroutine in the ThisWorkbook class as:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
--- code
--- code
End Sub

Now I have another subroutine in Module 1 of my workbook:

Sub Userform()
-- Code
-- Code
If Err = 0 Then
Call Workbook_BeforeClose(True)
Exit Sub
End If
End Sub


Now I want to call the subroutine Workbook_BeforeClose from within the
Userform() routine, if there is an Error is encountered -- basically i
want to close the entire workbook.
Can somebody shed light on how to achieve this ?
Thanks,
Ravi
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with Calling a subroutine in the ThisWorkbook Class

Thanks Jim for your advice,

I tried "ThisWorkbook.Close", but probably I want to quit the Excel
Application also and not just close the workbook. Do you think
Application.Quit would work, but I would like to invoke the
Workbook_BeforeClose also since I want to execute the code in that
subroutine ( it restores certain toolbars) before quitting excel.

Thanks,
Ravi

On Feb 1, 11:43*am, "Jim Cone" wrote:
Instead of... Call Workbook_BeforeClose(True)
Use... ThisWorkbook.Close
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"freshforlife"
wrote in message
Hi All,
I have defined a subroutine in the ThisWorkbook class as:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
--- code
--- code
End Sub

Now I have another subroutine in Module 1 of my workbook:

Sub Userform()
-- Code
-- Code
If Err = 0 Then *
* * Call Workbook_BeforeClose(True)
* * Exit Sub
End If
End Sub

Now I want to call the subroutine Workbook_BeforeClose from within the
Userform() routine, if there is an Error is encountered -- basically i
want to close the entire workbook.
Can somebody shed light on how to achieve this ?
Thanks,
Ravi


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Help with Calling a subroutine in the ThisWorkbook Class

Ravi,
Close all workbooks before using Application.Quit.
The BeforeClose event runs (as the name implies) before the
actual workbook closure takes place.

You also need to decide whether each workbook is to be saved...
Workbooks("Ravioli").Close savechanges: = True ' or False

If you don't specify whether to save the book then Excel will pop up
a message asking what to do.
That stops everything until the message is answered.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"freshforlife"
wrote in message
Thanks Jim for your advice,

I tried "ThisWorkbook.Close", but probably I want to quit the Excel
Application also and not just close the workbook. Do you think
Application.Quit would work, but I would like to invoke the
Workbook_BeforeClose also since I want to execute the code in that
subroutine ( it restores certain toolbars) before quitting excel.

Thanks,
Ravi

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with Calling a subroutine in the ThisWorkbook Class

Thanks Jim.......

I kind of implemented your idea partially, even though I could get the
desired thing to run by just "Application.Quit" ----

In Fact i closed all other workbooks except the Workbook which
contained the Workbook_BeforeClose() and other VBA subroutines........

and then i invoked the Application.Quit

-- Although by writing application.Quit -- I could close all workbooks
and exit Excel also.

Regards,
Ravi


On Feb 1, 12:31*pm, "Jim Cone" wrote:
Ravi,
Close all workbooks before using Application.Quit.
The BeforeClose event runs (as the name implies) before the
actual workbook closure takes place.

You also need to decide whether each workbook is to be saved...
* * *Workbooks("Ravioli").Close savechanges: = True ' or False

If you don't specify whether to save the book then Excel will pop up
a message asking what to do. *
That stops everything until the message is answered.
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"freshforlife"
wrote in message
Thanks Jim for your advice,

I tried "ThisWorkbook.Close", but probably I want to quit the Excel
Application also and not just close the workbook. Do you think
Application.Quit would work, but I would like to invoke the
Workbook_BeforeClose also since I want to execute the code in that
subroutine ( it restores certain toolbars) before quitting excel.

Thanks,
Ravi




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Help with Calling a subroutine in the ThisWorkbook Class

Why Application.Quit? One of the golden rules of programming is that you do
not want to effect what is going on outside of your little area. What if the
user is working on other things besides your spreadsheet? By quitting the
application you are going outside of your world and infringing on theirs.

Just my 2 cents but if you gave me that spreadsheet to use I would give it
right back to you and ask you to fix it so that your spreadsheet has no
effect on anything else I might be doing.
--
HTH...

Jim Thomlinson


"freshforlife" wrote:

Thanks Jim for your advice,

I tried "ThisWorkbook.Close", but probably I want to quit the Excel
Application also and not just close the workbook. Do you think
Application.Quit would work, but I would like to invoke the
Workbook_BeforeClose also since I want to execute the code in that
subroutine ( it restores certain toolbars) before quitting excel.

Thanks,
Ravi

On Feb 1, 11:43 am, "Jim Cone" wrote:
Instead of... Call Workbook_BeforeClose(True)
Use... ThisWorkbook.Close
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"freshforlife"
wrote in message
Hi All,
I have defined a subroutine in the ThisWorkbook class as:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
--- code
--- code
End Sub

Now I have another subroutine in Module 1 of my workbook:

Sub Userform()
-- Code
-- Code
If Err = 0 Then
Call Workbook_BeforeClose(True)
Exit Sub
End If
End Sub

Now I want to call the subroutine Workbook_BeforeClose from within the
Userform() routine, if there is an Error is encountered -- basically i
want to close the entire workbook.
Can somebody shed light on how to achieve this ?
Thanks,
Ravi



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Help with Calling a subroutine in the ThisWorkbook Class

Thanks Jim T ............

Although I solved my problem with Closing Workbooks +
Application.Quit, I see that you have a valid point.

Thanks for your valuable 2 cents.


On Feb 1, 1:38*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Why Application.Quit? One of the golden rules of programming is that you do
not want to effect what is going on outside of your little area. What if the
user is working on other things besides your spreadsheet? By quitting the
application you are going outside of your world and infringing on theirs.

Just my 2 cents but if you gave me that spreadsheet to use I would give it
right back to you and ask you to fix it so that your spreadsheet has no
effect on anything else I might be doing.
--
HTH...

Jim Thomlinson



"freshforlife" wrote:
Thanks Jim for your advice,


I tried "ThisWorkbook.Close", but probably I want to quit the Excel
Application also and not just close the workbook. Do you think
Application.Quit would work, but I would like to invoke the
Workbook_BeforeClose also since I want to execute the code in that
subroutine ( it restores certain toolbars) before quitting excel.


Thanks,
Ravi


On Feb 1, 11:43 am, "Jim Cone" wrote:
Instead of... Call Workbook_BeforeClose(True)
Use... ThisWorkbook.Close
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"freshforlife"
wrote in message
Hi All,
I have defined a subroutine in the ThisWorkbook class as:


Private Sub Workbook_BeforeClose(Cancel As Boolean)
--- code
--- code
End Sub


Now I have another subroutine in Module 1 of my workbook:


Sub Userform()
-- Code
-- Code
If Err = 0 Then *
* * Call Workbook_BeforeClose(True)
* * Exit Sub
End If
End Sub


Now I want to call the subroutine Workbook_BeforeClose from within the
Userform() routine, if there is an Error is encountered -- basically i
want to close the entire workbook.
Can somebody shed light on how to achieve this ?
Thanks,
Ravi- Hide quoted text -


- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a VBA add in from a macro subroutine [email protected] Excel Programming 1 April 6th 07 10:09 PM
HELP! Calling subroutine in different workbook ChrisWalker Excel Programming 3 March 1st 06 11:32 AM
Calling a subroutine in a loop Jeff@DE Excel Programming 1 January 9th 06 09:56 AM
calling a subroutine outside a spreadsheet dino Excel Programming 5 June 11th 04 06:14 PM
Function Calling Subroutine Curare Excel Programming 1 February 24th 04 07:11 PM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"