Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to kill Excel from Access 1

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
GB
I have VBA codes in Access 2000 that would declare an object and set it to an Excel workbook as follows. It would crash if the excel spreadsheet is already opened manually in Excel.
How could I detect whether such worksheet is opened and if so, CLOSE it??

Code:
dim xlBk as Excel.Workbook
Set xlBk = Workbooks.Open(file)
Set xlSheet = xlBk.Worksheets(1)
 
One way that springs to mind is to use the GetObject function like so

Set xlBk = GetObject("C:\documents\YourSS.xls")

if it returns an object you can either use it then or close it using 'xlBk.Close'. If it doesn't return an object then you have a trappable error that will let you know it's not open. Durkin
alandurkin@bigpond.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top