+ Reply to Thread
Results 1 to 9 of 9

closing the blank instance of Excel via VBA

Hybrid View

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    closing the blank instance of Excel via VBA

    Hello

    For a certain reason I creating "Excel.Application"
    then opening a workbook with workbooks.open method
    but the book opens in a new instance of Excel ,,ok ok that is ok

    What I want is simply to check if there are some blank instances of Excel then close them is it possible?
    coz when I use :
    Application.Quit
    It closes the workbook also
    rephrased question:Can we close the blank instances of Excel?,,,if they exist for some reasons
    Please do not think about other options to avoid blank instances
    this exists and now how to close it without closing the workbook that is opened in another instance of Excel?

    Best Regards
    Imran Bhatti
    Teach me Excel VBA

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,299

    Re: closing the blank instance of Excel via VBA

    Are you somehow having blank workbooks opening and now need to close all except active one
    Private Sub Workbook_Open()
    Dim WB As Workbook
    For Each WB In Workbooks
         If Not (WB Is ActiveWorkbook) Then WB.Close
    Next
    End Sub
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: closing the blank instance of Excel via VBA

    Thanks Sintek

    Sorry I should have clarify what I meant by blanks instances of Excel.
    If we open a workbook and then close it by clicking the X button of the workbook and not the top excel X button .then we see a blank excel instance.I have such instance with a separate window.let me attach 2 photos of'em.
    The above is the blank instance that does not have a workbook at all.
    The other one has a workbook in it and I don't want to close it.
    Attached Images Attached Images

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,299

    Re: closing the blank instance of Excel via VBA

    Why are you opening blank windows?

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: closing the blank instance of Excel via VBA

    Sintek I am creating a vbs file with macro. closing the workbook and then reopening it but this time with the vbs script.and vbs script is also controlled from the macro in the workbook. vbs code that is generated and the run is
     On Error Resume Next
    
    Dim WshShell
    Set WshShell = CreateObject("WScript.Shell")
    
    MsgBox "Click OK to complete the setup process."
    Dim strRegPath
    strRegPath = some action here
    WScript.echo strRegPath
    WshShell.RegWrite strRegPath, 1, "REG_DWORD"
    
    If Err.Code <> o Then
    End If
    
    Set objExcel = CreateObject("Excel.Application")
    With objExcel
    .Workbooks.Open("C:\Users\Bhatti\Desktop\Copy of 123 (1).xlsm")
    .Visible = True
    End With
    objExcel.windowstate=-4137

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: closing the blank instance of Excel via VBA

    What are you actually trying to do?
    If posting code please use code tags, see here.

  7. #7
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: closing the blank instance of Excel via VBA

    Found the solution myself.Thanks for your time as well.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,299

    Re: closing the blank instance of Excel via VBA

    Please post your solution so that others may learn from this Thread.

  9. #9
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: closing the blank instance of Excel via VBA

    Well Sintek
    I was actually writing a sub routine that will close the application but in between that routine I was creating a VBScript and then closing the workbook.
    There I used "Application.Quit"
    I had mentioned in my first post in the same thread that I had tried "Applicatioin.Quit" but no effect.But I was writing that in the VBSript and not in the main routine.
    In the main routine there was still "thisworkbook.close" which was replaced by "Applicatioin.Quit"


    simply speaking: [QUOTE]The problem was that I was not quitting the Application.[/QUOTE]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2016, 01:31 AM
  2. Replies: 1
    Last Post: 03-25-2016, 01:16 AM
  3. Excel 2013 not closing after closing workbook
    By SBennett212 in forum Excel General
    Replies: 4
    Last Post: 04-04-2015, 11:07 AM
  4. Replies: 3
    Last Post: 07-15-2014, 09:50 AM
  5. Replies: 8
    Last Post: 04-25-2012, 01:05 PM
  6. Excel Instance not closing in task manager.
    By MattShoreson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2009, 11:26 AM
  7. Closing Excel Instance
    By harkit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2005, 12:05 PM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1