运行时错误 13 - 尝试编辑 Lotus Notes 的富文本项目时类型不匹配

Runtime Error 13 - Type Mismatch when trying to edit richtext item of Lotus Notes

我正在尝试通过 VBA 编辑现有的笔记文档,然后自动发送它。

我已经创建了几乎所有内容 - 只需要弄清楚如何在 richtext 元素中的特定位置添加特定文本。

Sub sendMail() 'inputIndID As String, inputRecipient As String, inputIncDescription As String)

Dim mailDB As Object
Dim mailToSend As Object
Dim body As Object
Dim session As Object
Dim view As Object
Dim entries As Object
Dim docIDs() As String
Dim docSubjects() As String
Dim incID, incDescription As String
Dim element As String
Dim bodyNavigator As Object

incID = "<INC-ID>"
incDescription = "<INC-Betreff>"

'Start a session to notes
Set session = CreateObject("Notes.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
'Call Session.Initialize
'or use below to supply password of the current ID

'Open the mail database in notes
Set mailDB = session.GetDatabase("Eschen10/Presta", "mail\qcpcsupport.nsf")
If mailDB.IsOpen = False Then
    Call mailDB.Open
End If

'Search for all the messages in the folder "Umfrage"
Set view = mailDB.GetView("Umfrage")
Set entries = view.AllEntries
If entries.Count = 0 Then
    MsgBox "Keine Nachricht im Umfrage Ordner."
End If
ReDim docIDs(entries.Count - 1)
ReDim docSubjects(entries.Count - 1)
Set entry = entries.GetFirstEntry
Do Until entry Is Nothing
    docIDs(i) = entry.NoteID
    docSubjects(i) = entry.Document.GetItemValue("Subject")(0) 'based on standard R5 mail template column order
    'If the documents title matches the searched one it will be taken and worked with later
    If docSubjects(i) = "Umfrage PC-Support Servicequalität" Then
        Set mailToSend = entry.Document
    End If
    i = i + 1
    Set entry = entries.GetNextEntry(entry)
Loop


'Set the recipient
Call mailToSend.ReplaceItemValue("SendTo", "simon.hartmann@thyssenkrupp.com")

'Get and change the body content
Set body = mailToSend.GetFirstItem("Body")
Set bodyNavigator = body.CreateNavigator()

'Replace markers with correct text

element = "<"

If (body.Type = RICHTEXT) Then
    Call bodyNavigator.FindFirstString(element)
    Call body.BeginInsert(bodyNavigator, True)
    Call body.AppendText("123456")
    Call bodyNavigator.FindNextString(element)
    Call body.BeginInsert(bodyNavigator, True)
    Call body.AppendText("Antrag Guest WLAN")
End If


'Example to save the message (optional)
mailToSend.SaveMessageOnSend = True

'Send the document
'Gets the mail to appear in the Sent items folder
mailToSend.Save True, False
Call mailToSend.ReplaceItemValue("PostedDate", Now())
Call mailToSend.Send(False)

'changes the body back and saves the document in the folder "Umfrage" so it can be resent next time
Call mailToSend.PutInFolder("Umfrage")

'Clean Up
Set mailDB = Nothing
Set mailToSend = Nothing
Set body = Nothing
Set session = Nothing


End Sub

目前我在以下行失败:

Call body.BeginInsert(bodyNavigator, True)

我收到错误 - 运行时错误 13 - 类型不匹配

我也已经尝试为所有变量提供 Lotus Notes 的正确数据类型 - 但后来我遇到了每个变量的问题。

有什么方法可以 "force" bodynavigator 的类型正确吗?或者我哪里有错误?我是不是错过了图书馆什么的?

提前致谢!!!

此致, 西蒙

你读过 documentation for NotesRichtextNavigator 了吗?

您在那里找到以下信息:

Parameters
target$

String. The search string.

options$

Long. Any of the following. Specify multiple options by combining them with addition or logical ORs.

  • RT_FIND_ACCENTINSENSITIVE (4) (default is accent sensitive)
  • RT_FIND_CASEINSENSITIVE (1) (default is case sensitive)
  • RT_FIND_PITCHINSENSITIVE (2) (default is pitch insensitive)

因此:您的第二个参数“true”只是错误的类型...因此类型不匹配...