Declare @WordObject int, @RetCode int, @Document int , @Filename varchar(255)
Exec @RetCode = sp_OACreate 'Word.Application', @WordObject OUTPUT, 4
SELECT @WordObject
Exec @RetCode = sp_OAMethod @WordObject, 'Documents.Add',
@Document OUTPUT
exec @RetCode = sp_OAMethod @WordObject,'Selection.TypeText("Created from within SQL Server SP using OLE Automation.")'
SELECT @Filename = 'C:\Documents and Settings\skeerthi\Desktop\yes.doc'
Exec @RetCode = sp_OAMethod @WordObject,'ActiveDocument.SaveAs' , NULL , @Filename
Exec @RetCode = sp_OAMethod @WordObject, 'Quit'
Exec sp_OADestroy @WordObject
Exec @RetCode = sp_OAMethod @WordObject, 'Quit'
Exec sp_OADestroy @WordObject
Exec @RetCode = sp_OACreate 'Word.Application', @WordObject OUTPUT, 4
SELECT @WordObject
Exec @RetCode = sp_OAMethod @WordObject, 'Documents.Add',
@Document OUTPUT
exec @RetCode = sp_OAMethod @WordObject,'Selection.TypeText("Created from within SQL Server SP using OLE Automation.")'
SELECT @Filename = 'C:\Documents and Settings\skeerthi\Desktop\yes.doc'
Exec @RetCode = sp_OAMethod @WordObject,'ActiveDocument.SaveAs' , NULL , @Filename
Exec @RetCode = sp_OAMethod @WordObject, 'Quit'
Exec sp_OADestroy @WordObject
Exec @RetCode = sp_OAMethod @WordObject, 'Quit'
Exec sp_OADestroy @WordObject
No comments:
Post a Comment