Consulting

Results 1 to 5 of 5

Thread: Solved: How do I 'close' an open workbook?

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location

    Solved: How do I 'close' an open workbook?

    Hello again

    Does anyone know how I should 'close' an open workbook?

    I have tried the following code but there is a syntax error in my attempt at the 'close' command'.

    I can comment out the offending line and the code runs OK, but it leaves the workbook open.
    Many thanks
    Lester

    [vba]
    Sub ImportLookUp()
    Dim oWB As Workbook
    Dim oThis As Workbook

    Set oThis = ActiveWorkbook
    Set oWB = Workbooks.Open("G:\temp\ChargeRatesLookUp.xls")
    oWB.Sheets("Charge Rates Look-up").Copy after:=oThis.Worksheets(oThis.Worksheets.Count)
    'New line added below - but there's a syntax error
    Set oWB = Workbooks.Close("G:\temp\ChargeRatesLookUp.xls")
    End Sub
    [/vba]

  2. #2
    try it like this:
    [VBA]
    worksbooks("G:\temp\ChargeRatesLookUp.xls").close SaveChanges:=false/true
    [/VBA]

  3. #3
    opps, small mistake... workbooks

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You just need:
    oWb.Close
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Sorted! Both suggestions work. I'll go with rory's.
    Thanks to both of you.
    Cheers
    Lester.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •