创建doc文档并通过oleobject对象发送outlook

Here is some sample script.  The word document created is saved from a template doc previously created with specific bookmarks used to format the text.

oleobject lole_word
OLEObject lole_item, lole_attach, lole_outlook
string ls_file_name

lole_word = CREATE oleobject
lole_outlook = Create OLEObject
TRY
    lole_word.connecttonewobject('word.application')
CATCH (runtimeerror a)
    Messagebox('Error','Error connecting with MS Word. Process terminating.')
    RETURN -1
END TRY
lole_word.visible = FALSE // dont want to see word

ls_file = C:\temp\template.doc

If Not FileExists(ls_file) Then
    //ERROR CONDITION
     li_rc = MessageBox("File Not Found", "Cannot find document template: "+ls_file+"~r"+ "Do you want to select the template?", Question!, YesNo!, 2)
     If li_rc = 2 Then
        Return -1
     Else
        GetFileOpenName("Select Template File", ls_file, ls_file_name, ".DOC","Template Files, *.DOC")
        If Not FileExists(ls_file_name) Then
            // ERROR CONDITION
            MessageBox("Template File Not Found","Cannot find document: "+ ls_file_name)
           return -1
        End If
     End If
ELSE
    
End If

TRY
    lole_word.Documents.open(ls_file_name)
CATCH (runtimeerror b)
    Messagebox('Error','Error opening ' + ls_file_name + ' with MS Word. Process terminating.')
    RETURN -1
    
END TRY
lole_word.activedocument.bookmarks.item('vendor').range.text = ids_xdex.getitemstring(1,'vendordesc')

lole_word.activedocument.bookmarks.item('buyertext').range.text = ls_buyernote
lole_word.activedocument.bookmarks.item('text').range.text = ls_data
lole_word.activedocument.bookmarks.item('legend').range.text = '* D - De Expedite, E - Expedite, C - Cancel'
lole_word.activedocument.bookmarks.item('buyer').range.text = ls_name
lole_word.activedocument.bookmarks.item('buyerfax').range.text = ls_fax
lole_word.activedocument.bookmarks.item('buyeremail').range.text = ls_email


is_doc = ls_file + ls_doc
// save document before processing further
TRY
    lole_word.activedocument.saveas(is_doc)
CATCH (runtimeerror c)
    Messagebox('Error','Error saving document ' + is_doc + '. Process terminating.')
    RETURN -1
END TRY
TRY
    lole_word.activedocument.saveas('P:\temp.doc') // save 'dummy' so 'real' document is not locked
CATCH (runtimeerror d)
    Messagebox('Error','Error saving temp document. Process terminating.')
    RETURN -1
END TRY

lole_word.activedocument.printout()    // print from word


//Connect to Outlook session using 'Outlook.Application'
li_rc = lole_outlook.ConnectToNewObject("outlook.application")

If li_rc <> 0 Then
    // ERROR CONDITION
          Messagebox("Outlook Error",string(li_rc))
          Destroy lole_outlook
          Return li_rc
End If
//Creates a new mail Item
lole_item = lole_outlook.CreateItem(0)
//Set the subject line of message
lole_item.Subject = "Expedite / De Expedite Notice"
//Body of mail message
lole_item.Body = "Please review the attached file and advise: "+Char(13)
//Recipient(s) Use a semicolon to separate multiple recipients
lole_item.To = dw_vendorfax.getitemstring(1,'contactemail')
lole_attach = lole_item.Attachments
lole_attach.add(is_doc)
lole_item.Display //displays the message
//    lole_item.Send //sends the message
lole_outlook.disconnectobject()

DESTROY lole_outlook
DESTROY lole_word

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a123lm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值