Excel VBA - Closing Entire Spreadsheet From UserForm


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Excel VBA - Closing Entire Spreadsheet From UserForm

  1. #1
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666

    Excel VBA - Closing Entire Spreadsheet From UserForm

    This is the first time I've ever used a UserForm with Excel (or actually done any coding in VBA for that matter).

    I have a UserForm. When I close it, the underlying excel spreadsheet (which is completely blank and used for no other purpose than as a home for the userform) is still displayed on the screen and must be closed as well.

    On the userform, I tried
    Code:
    Private Sub UserForm_Deactivate()
    Workbooks.Close
    End Sub
    But that didn't do anything.

    Can I cleanly close both when I shutdown the userform?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Never mind. I got it.
    Code:
    Application.Quit
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    If you don't want to exit excel, just close the workbook then use:
    Code:
    ActiveWorkbook.Close
    '..Or..
    Workbooks(1).Close
    Remember Workbooks is a collection so you need to specify which workbook, even if only one is open.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    That is good to know, but I think in this instance, closing Excel would be the way to go.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 0
    Last Post: 05-15-2008, 05:24 PM
  2. Excel VBA, Userform w/ ComoboBox
    By scgamecock in forum VB Classic
    Replies: 1
    Last Post: 10-24-2007, 02:40 AM
  3. Workbook not Closing Properly by Excel VBA
    By blayne in forum VB Classic
    Replies: 1
    Last Post: 11-17-2005, 07:14 PM
  4. Excel spreadsheet on web form
    By Nishith Prabhakar in forum ASP.NET
    Replies: 0
    Last Post: 06-03-2003, 10:59 AM
  5. Closing Excel
    By Miroslav St. Jeliaskoff in forum .NET
    Replies: 4
    Last Post: 10-03-2002, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center