Vba 在Lotus Notes电子邮件中将Word文档作为附件发送

Vba 在Lotus Notes电子邮件中将Word文档作为附件发送,vba,ms-word,lotus-notes,sendmail,lotus,Vba,Ms Word,Lotus Notes,Sendmail,Lotus,我有一个Word文档,其中包含一个电子邮件地址,我需要使用Lotus Notes将此文档发送给不同的人,Lotus Notes是我的默认电子邮件客户端,我已经连接到它。如果可能的话,我还想以PDF格式发送该文件 请有人帮我写一个宏,将文档附加为PDF格式,并使用Lotus Notes将其发送到Word文档中已经存在的所有电子邮件地址 我曾尝试使用在本论坛中找到的一段代码,但无法获得电子邮件地址: Sub Send_mail_recipients() Dim Text As String Dim

我有一个Word文档,其中包含一个电子邮件地址,我需要使用Lotus Notes将此文档发送给不同的人,Lotus Notes是我的默认电子邮件客户端,我已经连接到它。如果可能的话,我还想以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

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

1从Word文档中读取电子邮件地址。既然您知道文档是什么样子,就必须自己解决这个问题。将地址存储在字符串数组中

2创建当前打开文档的PDF。我假设Word现在具有与OpenOffice相同的功能,并且您可以简单地将文档导出为PDF文件。应该不难写。只需记住存储您创建的PDF文件的名称和路径。保存文件时,您应该强制输入文件名,最好将文件放在临时文件夹中,以便以后获取文件

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

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

可能是一个很好的起点,请注意,堆栈溢出不是代码编写服务,而是帮助修复已尝试的代码。在我看来,该代码就像VBA for Excel。。。