DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649

    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,649
    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,252
    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,649
    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, 04:24 PM
  2. Excel VBA, Userform w/ ComoboBox
    By scgamecock in forum VB Classic
    Replies: 1
    Last Post: 10-24-2007, 01:40 AM
  3. Workbook not Closing Properly by Excel VBA
    By blayne in forum VB Classic
    Replies: 1
    Last Post: 11-17-2005, 06:14 PM
  4. Excel spreadsheet on web form
    By Nishith Prabhakar in forum ASP.NET
    Replies: 0
    Last Post: 06-03-2003, 09:59 AM
  5. Closing Excel
    By Miroslav St. Jeliaskoff in forum .NET
    Replies: 4
    Last Post: 10-03-2002, 09:08 AM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links