PDA

View Full Version : Solved: How do I 'close' an open workbook?



Lester
11-08-2007, 09:32 AM
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


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

robsimons
11-08-2007, 09:34 AM
try it like this:

worksbooks("G:\temp\ChargeRatesLookUp.xls").close SaveChanges:=false/true

robsimons
11-08-2007, 09:38 AM
opps, small mistake... workbooks

rory
11-08-2007, 09:41 AM
You just need:
oWb.Close

Lester
11-08-2007, 09:59 AM
Sorted! Both suggestions work. I'll go with rory's.
Thanks to both of you.
Cheers
Lester.