View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
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