+ Reply to Thread
Results 1 to 8 of 8

ActiveWorkbook.close is closing all workbooks

  1. #1
    Registered User
    Join Date
    05-27-2017
    Location
    Cape Town
    MS-Off Ver
    16
    Posts
    6

    ActiveWorkbook.close is closing all workbooks

    Hi - I have a fairly complex workbook with a lot of code and something I changed has caused an error. When I execute a statement ActiveWorkbook.Close false it closes all my open workbooks in stead of just the active workbook. If I pause the macro just before this statement and close the workbook manually it also closes all open workbooks. However if I select the workbooks back and forth a few times then it only closes the active workbook. This is driving me nuts ... can anyone help.

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

    Re: ActiveWorkbook.close is closing all workbooks

    Hey there johnvn

    Welcome to the forum...
    Are you able to post your code snippet and a sample file upload...

    Edited...
    Why not set the wb in beginning of code and then use...
    Please Login or Register  to view this content.
    Last edited by sintek; 07-26-2017 at 11:00 AM.
    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
    Registered User
    Join Date
    05-27-2017
    Location
    Cape Town
    MS-Off Ver
    16
    Posts
    6

    Re: ActiveWorkbook.close is closing all workbooks

    Hi Sintek - thanks for the fast response.. here is the piece of code that closes the macro. As I mentioned, this piece of code has been working fine for some time. I presume that a change I made to some other code must have broken this. I might note that I have added a number of Shhet1.select, Sheets("Summary").select to try and force the correct sheet

    '------------------ Clean up & select Summary -------------------------
    Application.DisplayAlerts = True

    Sheets("Summary").Select
    Range("M13").Select

    Dim chk As Long, chk2 As Long

    chk = Range("L12")
    chk2 = Range("J12")


    wbCopyTo.Activate

    Sheet1.Select
    Range("M10").Value = chk
    Range("M11").Value = chk2

    Range("A3").Select
    Sheet1.Select
    Sheets("Summary").Select
    Application.CutCopyMode = False

    If Range("L12") = Range("M10") And Range("J12") = Range("M11") Then
    wbCopyFrom.Close False
    End If


    Application.Calculation = xlCalculationAutomatic ' Close file that was opened
    Application.ScreenUpdating = True

    Application.CommandBars.FindControl(ID:=549).Execute ' Turn Picture Snap to Grid on

    MsgBox "Import Complete!"
    Last edited by johnvn; 07-26-2017 at 11:07 AM.

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

    Re: ActiveWorkbook.close is closing all workbooks

    johnvn...

    Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window.
    Edit your post and highlight the part of code and add code tags #...
    With that been said...please explain to us in detail what you are trying to achieve...
    Last edited by sintek; 07-26-2017 at 01:03 PM.

  5. #5
    Registered User
    Join Date
    05-27-2017
    Location
    Cape Town
    MS-Off Ver
    16
    Posts
    6

    Re: ActiveWorkbook.close is closing all workbooks

    My apologies re: the code

    What is happening here is that I am importing data from a number of workbooks that are submitted to me on a daily basis. In the master workbook (wcCopyTo), I check 2 cells (L12 & J12) against two values (M10 & M11), and if they match then I close the workbook that I am importing from(wbCopyFrom)
    So the if then section checks that these are equal and if the values are correct it close the wbCopyFrom. If the values are not equal the the wbCopyFrom stays open to enable me to find the problem.

    The posted code (without tags ) is at the end of the import code.

    As you can see - the macro completes and shows the MsgBox but then wants to close the workbook. After the MsgBox is my End Sub. So no more code.

    I forgot to mention - if I comment out the wbFrom close statement the the workbook does not want to close


    end_imp.png

    next_after.png
    Last edited by johnvn; 07-26-2017 at 02:10 PM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: ActiveWorkbook.close is closing all workbooks

    Can we see the beginning of your code, which includes the Dim statements?

  7. #7
    Registered User
    Join Date
    05-27-2017
    Location
    Cape Town
    MS-Off Ver
    16
    Posts
    6

    Re: ActiveWorkbook.close is closing all workbooks

    Sure - here goes

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-27-2017
    Location
    Cape Town
    MS-Off Ver
    16
    Posts
    6

    Re: ActiveWorkbook.close is closing all workbooks

    Hi guys - my bad - I found my problem.

    I had the following code in my workbook

    Thanks for the help though.

    Please Login or Register  to view this content.

+ 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. Closing external csv object while moving contents in activeworkbook sheet
    By contactfornitish in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-15-2016, 10:57 AM
  2. [SOLVED] How can I completely close a specific workbook without closing other open workbooks
    By Sc0ut in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2016, 04:06 PM
  3. [SOLVED] ActiveWorkbook.Close is not real close :confused:
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2014, 01:02 PM
  4. [SOLVED] ActiveWorkbook.Close closing sheets, but not the window
    By mintymike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2014, 07:36 AM
  5. [SOLVED] Closing a Workbook from another workbook: Workbooks.close error: Subscript out of range
    By Coreyusa in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-14-2013, 06:45 PM
  6. Replies: 6
    Last Post: 02-15-2012, 07:52 AM
  7. close workbooks without closing excel ?
    By Clute in forum Excel General
    Replies: 2
    Last Post: 08-05-2006, 04:50 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