Results 1 to 2 of 2

Can't close an inactive Workbook - result in error 9

Threaded View

  1. #1
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    60

    Unhappy Can't close an inactive Workbook - result in error 9

    I have one WB open (ThisWorkbook) and the code bellows opens a 2nd one (cg.xlsm).
    It copies cells A1:A1000 and pastes them into ThisWorkbook starting at L1500 on sheet Target Sheet.
    This all works except for line above Sub , closing the captain_WB. How do I fix this?

    Additionally, if I want to open the WB I use "Workbooks.Open captain_WB" but I tried to close the WB using "Workbooks.Close captain_WB" as it would seem to mirror the open WB line but that didn't work either. Help is appreciated.

    Sub get_cg_report()
    
    Dim WBDest As Workbook
    Set WBDest = ThisWorkbook   
    Dim cg_WB
    
    captain_WB = "c:\users\myname\my documents\cg.xlsm"   
    Workbooks.Open captain_WB
    Sheets("sheet1").Range("A1:A1000").Copy        'copy a specific range
    WBDest.Activate                   'activate the target workbook
    Worksheets("Target Sheet").Range("L1500").PasteSpecial      'paste the range to cell a1500
    
    Workbooks(captain_WB).Close False
    end sub
    Last edited by gototcm; 01-23-2014 at 10:59 PM. Reason: typo

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA to Close Workbook if BOTH Workbook is inactive and VBA is Not Open
    By teblowtime in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2013, 10:09 AM
  2. Close inactive Workbook without workbook name
    By chrismann85 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2009, 10:08 AM
  3. Data Consolodation VBA - close inactive workbook
    By grahadw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2009, 12:38 PM
  4. Auto Close Workbook if inactive 5min
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2008, 01:36 PM
  5. Option in Excel to save a close a workbook inactive for 5 minutes
    By Patricia Peterson in forum Excel General
    Replies: 4
    Last Post: 01-05-2006, 01:00 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