+ Reply to Thread
Results 1 to 3 of 3

Object required when closing a workbook

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,083

    Object required when closing a workbook

    My code is erroring on the "Wkb.Close False" line with an "Object Required" error, and I can't figure out why. This is my attempt to condense a lot of previous code, so I'm sure I've done soemthing wrong, but it's not jumping out at me. I'd sure appreciate some wisdom on this one.
     ExpenseFolder = "\\12AUST1001FS01\SHARE10011\Budget\SOBUDGET\12MFR\Expense_Dtl_Reports\"
    
            FileNames = Array("BR1112_ExpDtl_JAS.xls", "BR1112_ExpDtl_KP.xls", "BR1112_ExpDtl_DG.xls", _
                              "BR1112_ExpDtl_BV.xls", "BR1112_ExpDtl_JL.xls", "BR1112_ExpDtl_KG.xls", "BR1112_ExpDtl_Orphan.xls")
    
            For Each Wkb In FileNames
                If Dir(ExpenseFolder & Wkb) <> "" Then
                    Workbooks.Open ExpenseFolder & Wkb, ReadOnly:=True, UpdateLinks:=True
                End If
                FilterData
                lrow = Cells(Rows.Count, 1).End(xlUp).Row
                If lrow > 1 Then
                    'copy the detail to Today's sheet
                    ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).EntireRow.Copy Destination:=Exp.Sheets("Today").Range("A65536").End(xlUp).Offset(1, 0)
                Else
                End If
                Application.CutCopyMode = False
                Wkb.Close False
    
            Next Wkb


    ---------- Post added at 11:48 AM ---------- Previous post was at 11:03 AM ----------

    Well, I figured it out. Instead of
    Wkb.Close False
    I put
    ActiveWorkbook.Close False
    . That did the trick!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Object required when closing a workbook

    jomili,

    The issue is that the variable Wkb is used to loop through the array of filenames. That makes it a string type variable and not a workbook object. To close the workbook, you'll need to use:
    Workbooks(Wkb).Close False


    ---------- Post added at 10:50 AM ---------- Previous post was at 10:50 AM ----------

    Looks like I posted a hair too late! Glad you got a working solution
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,083

    Re: Object required when closing a workbook

    Better late than never. Thanks for helping.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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