首页 文章

将Word Doc作为附件发送到Lotus Notes Email

提问于
浏览
-5

我有一个包含电子邮件地址的Word文档,我需要使用Lotus Notes将此文档发送给不同的人,Lotus Notes是我的默认电子邮件客户端,我已经连接到该客户端 . 如果可能的话,我也希望 send the document as a PDF .

请有人帮我写一个宏,将文档作为PDF附加,并使用Lotus Notes将其发送到Word文档中已有的所有电子邮件地址 .

我曾尝试使用我在此论坛中找到的一段代码,但未获取电子邮件地址:

Sub Send_mail_recipients()
Dim Text As String
Dim char As String
Dim rowcount, n_address, n_cells, Cell_Crt, CharNo As Integer
Dim Recipient(100) As Variant
 'With Application.ActiveWindow.Document
 'Activate the Document
  'n_address = 0
 Text = ""
  ActiveDocument.Tables(2).Select
     n_cells = Selection.Cells.Count
  For Cell_Crt = 1 To n_cells
 If Selection.Cells(Cell_Crt).Range.Text Like "*@*" Then
'Recipient(n_address) = Selection.Cells(Cell_Crt).Range.Text
Text = Text + Selection.Cells(Cell_Crt).Range.Text + ", "
'n_address = n_address + 1
End If
'Text = Selection.Cells(Cell_Crt).Range.Text
Next
End If

最后我决定附上一个excel文件 . excel文件附加到电子邮件地址,但我想将此excel文件作为PDF附加 . 我不知道该怎么做 . 这是用于将活动excel文件附加到电子邮件的代码

Sub LotusNotesExcelEmail()

Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim obAttachment As Object, EmbedObject As Object
Dim stSubject As Variant, stAttachment As String
Dim vaRecipient As Variant, vaMsg As Variant

Const EMBED_ATTACHMENT As Long = 1454

'Retrieve the path and filename of the active workbook.
 stAttachment = ActiveWorkbook.FullName

'Initiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")

'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL

'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument
Set obAttachment = noDocument.CreateRichTextItem("stAttachment")
Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "",  stAttachment)


    'Get the name of the recipient from the user.
    vaRecipient = Worksheets("Invitación_curso").Range("B8").Value

 'Add values to the created e-mail main properties.
 With noDocument
.Form = "Memo"
.SendTo = vaRecipient
.Subject = "Solicitud Invitación Curso "
.Body = "Estimado xxxxx. Adjuntamos solicitud de invitación a curso……………!"
 .SaveMessageOnSend = True
End With


'Send the e-mail.

 With noDocument
.PostedDate = Now()
.SEND 0, vaRecipient
 End With
 Dim myMessage As String
 myMessage = MsgBox("Está seguro de que quiere enviar este correo?",    vbYesNo, "Está seguro?")

 If myMessage = vbYes Then
     With noDocument
         .PostedDate = Now()
         .SEND 0, vaRecipient
     End With
End If


'Release objects from the memory.
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing

'Activate Excel for the user.
'AppActivate "Microsoft Excel"
'MsgBox "El mensaje de correo se ha enviado correctamente", vbOKOnly
End Sub

1 回答

  • 0

    与所有编程一样,将问题分解为更小的问题/步骤 . 然后一次解决其中一个问题 . 让我们来看看你的问题以及如何处理每个问题 . 当您打开特定文档时,我将假设您要在Word中运行VBA宏 .

    1)从Word文档中读取电子邮件地址 . 既然您知道文档的外观,那么您必须自己解决这个问题 . 将地址存储在一个数组(字符串)中 .

    2)创建当前打开文档的PDF . 我认为Word今天具有与OpenOffice相同的功能,您只需将文档导出为PDF文件即可 . 写起来应该不难 . 只需记住存储您创建的PDF的名称和路径(您应该在保存时强制使用文件名,最好还将文件放在临时文件夹中),以便稍后获取该文件 .

    3)使用COM中的Notes后端类生成新电子邮件,填充地址字段,主题和正文,并附加您在步骤2中创建的PDF . 您可以查看我编写的用于处理邮件通知的Lotusscript类,也许这可以帮助你:

    http://blog.texasswede.com/lotusscript-mail-notification-class/

    您需要记住的是,地址字段是多值字段 . 您只需将地址放在一个数组中,然后将该数组存储在该字段中 . 此外,如果要从当前登录的用户之外的其他用户发送电子邮件,则必须使用未记录的方法将电子邮件文档存储在mail.box中,而不是使用NotesDocument类的发送方法 .

相关问题