运行时错误13-尝试编辑Lotus Notes的RTF项时键入不匹配

时间:2019-06-11 08:33:59

标签: excel vba lotus richtext

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

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

delta

当前我在以下行中失败:

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

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

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

有没有办法我可以“强迫”身体导航器使用正确的类型?还是我在哪里犯了错误?我想念图书馆吗?

提前谢谢!

关于, 西蒙

1 个答案:

答案 0 :(得分:1)

您读过documentation for NotesRichtextNavigator吗?

您可以在此处找到以下信息:

  

参数
  目标$

     

字符串。搜索字符串。

     

选项$

     

长。以下任何一项。通过将它们与加法或逻辑或相结合来指定多个选项。

     
      
  • RT_FIND_ACCENTINSENSITIVE(4)(默认为重音符号)
  •   
  • RT_FIND_CASEINSENSITIVE(1)(默认值区分大小写)
  •   
  • RT_FIND_PITCHINSENSITIVE(2)(默认为对音高不敏感)
  •   

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