You could issue a
drop table Items1
within a Try-Catch block - ignore the error if it's saying the table does not exist. Not very elegant but it will work most of the time.
There is a "hidden" table that you could query
SELECT COUNT(*) as t from MsysObjects WHERE type in (1,4,5,6) AND name = 'Items1'
Drop the table if
t
is > 0.
Or, create the table explicitly (you will need to know up front what is on the sheet) and swap that query to be
INSERT INTO Items1 SELECT * FROM [Excel 8.0;DATABASE=C:\Book1.xls;HDR=NO;IMEX=1].[Sheet1$]
There will be issues with the last approach if the users move any columns around (in my experience, they
will do this)
Comment - these approaches are intended to work for when the table does not exist at all (first run of program) AND for subsequent runs. The first two suggestions assume that you do not want to retain any data from previous runs. The last suggestion
will retain data from previous runs (and is subject to the vagaries of users moving columns around)