vba lotus notes中将文具邮件正文复制到新邮件中的代码
vba code for copying body of a stationery mail into a new mail in lotus notes
我正在尝试创建一个宏,它将打开一个新的 Lotus Notes 邮件,将某些文件附加到它,并从信纸邮件中复制和粘贴正文。
我卡在了最后一部分,我必须复制文具邮件的正文并将其粘贴到我创建的新邮件中。
下面是我试过的代码,但是只能附加文件,无法从文具中复制正文
感谢任何帮助.......
isattached = False
Application.ScreenUpdating = False
'Start Lotus Notes Session
Set nSession = CreateObject("Notes.NotesSession")
On Error GoTo err_send
Set nMailDb = nSession.GetDatabase("", "mailin/GBG180.nsf")
' Open the Stationery View
Set nView = nMailDb.GetView("Stationery")
Set nWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set nCursor = nView.GetFirstDocument
Do While Not nCursor Is Nothing
' get stationery value
StationeryName = nCursor.GetItemValue("MailStationeryName")(0)
' match form template selection versus stationery
If StationeryName = St_name Then
Set nMailDoc = nMailDb.CreateDocument("Memo")
Set AttachME = nMailDoc.CreateRichTextItem("ATTACHMENT")
'Open the PDF folder and attach the files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(PdfPath)
For Each objFile In objFolder.Files
Set EmbedObj = AttachME.EmbedObject(1454, "", PdfPath & objFile.Name)
isattached = True
Application.Wait (15)
Next
subjectname = policy_num & "-" & aname & "-FoS Invoice & Wording" & " " & Format(DateValue(Now()), "YYYY") & "- Confidential"
If (isattached) Then
'Set nMailDoc = nWorkspace.EDITDOCUMENT(True, nCursor)
nMailDoc.Subject = subjectname
Else
Set nMailDoc = Nothing
Set AttachME = Nothing
Exit Function
End If
nMailDoc.Save True, True, False
Set nMailDoc = Nothing
Set nCursor = Nothing
GoTo nMail_OK
Else
Set nCursor = nView.GetNextDocument(nCursor)
End If
Loop
在 Domino 中,有用于存储数据的默认项名称。邮件中的正文(包括所有附件)始终称为 "Body",而不是您的示例中的 "ATTACHMENTS"。
您需要替换这些行
Set AttachME = nMailDoc.CreateRichTextItem("ATTACHMENT")
'Open the PDF folder and attach the files
...
有了这些
Dim bodyStationary as NotesRichtextItem
'- get the richtext from the stationary
Set bodyStationary = nCursor.GetFirstItem( "Body" )
'- create richtextitem in new document
Set AttachME = nMailDoc.CreateRichTextItem("Body")
'- append the stationary
Call AttachMe.AppendRTItem( bodyStationary )
'- add the attachments
'Open the PDF folder and attach the files
...
如果您希望附件位于文具的正文上方,只需将 AppendRTItem 移至 Foreach- 循环下方即可。
在这种情况下不要忘记添加 Attachme.AddNewline( 2 )
,否则文本将直接跟在附件之后。
我正在尝试创建一个宏,它将打开一个新的 Lotus Notes 邮件,将某些文件附加到它,并从信纸邮件中复制和粘贴正文。
我卡在了最后一部分,我必须复制文具邮件的正文并将其粘贴到我创建的新邮件中。
下面是我试过的代码,但是只能附加文件,无法从文具中复制正文
感谢任何帮助.......
isattached = False
Application.ScreenUpdating = False
'Start Lotus Notes Session
Set nSession = CreateObject("Notes.NotesSession")
On Error GoTo err_send
Set nMailDb = nSession.GetDatabase("", "mailin/GBG180.nsf")
' Open the Stationery View
Set nView = nMailDb.GetView("Stationery")
Set nWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set nCursor = nView.GetFirstDocument
Do While Not nCursor Is Nothing
' get stationery value
StationeryName = nCursor.GetItemValue("MailStationeryName")(0)
' match form template selection versus stationery
If StationeryName = St_name Then
Set nMailDoc = nMailDb.CreateDocument("Memo")
Set AttachME = nMailDoc.CreateRichTextItem("ATTACHMENT")
'Open the PDF folder and attach the files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(PdfPath)
For Each objFile In objFolder.Files
Set EmbedObj = AttachME.EmbedObject(1454, "", PdfPath & objFile.Name)
isattached = True
Application.Wait (15)
Next
subjectname = policy_num & "-" & aname & "-FoS Invoice & Wording" & " " & Format(DateValue(Now()), "YYYY") & "- Confidential"
If (isattached) Then
'Set nMailDoc = nWorkspace.EDITDOCUMENT(True, nCursor)
nMailDoc.Subject = subjectname
Else
Set nMailDoc = Nothing
Set AttachME = Nothing
Exit Function
End If
nMailDoc.Save True, True, False
Set nMailDoc = Nothing
Set nCursor = Nothing
GoTo nMail_OK
Else
Set nCursor = nView.GetNextDocument(nCursor)
End If
Loop
在 Domino 中,有用于存储数据的默认项名称。邮件中的正文(包括所有附件)始终称为 "Body",而不是您的示例中的 "ATTACHMENTS"。
您需要替换这些行
Set AttachME = nMailDoc.CreateRichTextItem("ATTACHMENT")
'Open the PDF folder and attach the files
...
有了这些
Dim bodyStationary as NotesRichtextItem
'- get the richtext from the stationary
Set bodyStationary = nCursor.GetFirstItem( "Body" )
'- create richtextitem in new document
Set AttachME = nMailDoc.CreateRichTextItem("Body")
'- append the stationary
Call AttachMe.AppendRTItem( bodyStationary )
'- add the attachments
'Open the PDF folder and attach the files
...
如果您希望附件位于文具的正文上方,只需将 AppendRTItem 移至 Foreach- 循环下方即可。
在这种情况下不要忘记添加 Attachme.AddNewline( 2 )
,否则文本将直接跟在附件之后。