PDA

View Full Version : Delete automatically opened workbook



jolivanes
01-08-2010, 01:01 AM
With the following code I get information from a .mdb file



Workbooks.OpenDatabase Filename:="C:\C\SomeFile.MDB", CommandText:=Array( _
"SomeParams"), CommandType:=xlCmdTable


The workbook opened by above code needs to be deleted after the following:



Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(, 16)).Copy
Windows("AnotherWorkbook.xls").Activate
Range("A1").Select
ActiveSheet.Paste


The workbook name could be anything from Book1, Book2, Book3 etc etc.
How would I go about this?

Thank you very much in advance

Regards
John

Bob Phillips
01-08-2010, 03:39 AM
Workbooks.OpenDatabase Filename:="C:\C\SomeFile.MDB", CommandText:=Array( _
"SomeParams"), CommandType:=xlCmdTable
Set wb = ActiveWorkbook



Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(, 16)).Copy
Windows("AnotherWorkbook.xls").Activate
Range("A1").Select
ActiveSheet.Paste
sh.Close SaveChanges:=False

jolivanes
01-08-2010, 05:13 AM
Hi Bob.

Changed


sh.Close SaveChanges:=False


to



wb.Close SaveChanges:=False


and all is OK.

Thank you very much

Regards

John

Bob Phillips
01-08-2010, 05:54 AM
Yeah, that would help :)

jolivanes
01-08-2010, 06:23 AM
You were not testing me?

John

Bob Phillips
01-08-2010, 06:39 AM
No, just being sloppy!