February 8, 2012 at 8:55 am
Hi All,
I have some script I want to use to format an excel sheet before mailing. It errors on sp_OACreatek, the code looks like
IF @rs IS NULL SET @strErrorMessage='Auto-fit,format dt and make columns bold'
SET @objErrorObject=@objWorkSheet
SET @command= 'Rows("1:1").Select
Selection.Font.Bold = True
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").Select
Selection.NumberFormat = "m/d/yyyy"'
IF @rs IS NULL EXECUTE master..xp_cmdshell @Command, no_output
IF @rs IS NULL
SET @strErrorMessage='Saving the workbook as "'+@filename+'"'
SET @objErrorObject=@objRange
SET @command = 'SaveAs("' + @filename + '")'
IF @rs IS NULL EXEC @rs=sp_OAMethod @objWorkBook, @command -------
IF @rs IS NULL SET @strErrorMessage='closing Excel '
SET @objErrorObject=@objExcel
EXEC @rs =sp_OAMethod @objWorkBook, 'Close' -----
EXEC sp_OAMethod @objExcel, 'Close' -----
On every call of sp_OAMethod I get the follwing error
Msg 10019, Level 16, State 0, Line 0
sp_OACreate has not yet been called successfully for this command batch.
Any pointers will be appreciated!
R
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply