i have just added the error message generation in your code. try to execute it and check what error its generate
DECLARE @objExcel INT,@hr INT,@command VARCHAR(255),@strErrorMessage VARCHAR(255),@objErrorObject INT,@objConnection INT,@bucket INT,
@DDL VARCHAR(2000),@DataSource VARCHAR(100),@Worksheet VARCHAR(100)=NULL,@ConnectionString VARCHAR(255), @document int
Select @ConnectionString = 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%DataSource;Extended Properties="Excel 12.0 XML;HDR=YES"',
@DDL='Create table CambridgePubs(Pubname Text, Address Text, Postcode Text)',
@DataSource ='C:\CambridgePubs.xlsx'
SELECT @ConnectionString = REPLACE (@ConnectionString, '%DataSource', @DataSource)
print @ConnectionString
EXEC @hr = sp_OACreate 'ADODB.Connection', @objconnection OUT
print @hr
EXEC @hr=sp_OASetProperty @objconnection,'ConnectionString', @ConnectionString
print @hr
print @objconnection
EXEC @hr=sp_OAMethod @objconnection, 'Open'
print @hr
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @objconnection
Return
END;
EXEC @hr=sp_OAMethod @objconnection, 'Execute',@Bucket out , @DDL
print @hr
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @objconnection
Return
END;
If the error is something like this
0x800A0E7AADODB.ConnectionProvider cannot be found. It may not be properly installed.
Then i believe you are 64bit SQL SERVER, with 32 bit access driver you need a 64bit driver.
Download "AccessDatabaseEngine_X64.exe" from http://www.microsoft.com/en-gb/download/details.aspx?id=13255