首页 > 解决方案 > Excel VBA 代码:系统错误(服务器抛出异常)

问题描述

我对 VBA 编码有点陌生。我有一个 excel 文件,其中有一个用户列表,通过勾选相关复选框自动向其发送电子邮件请求他们的验证。

我设法获得了以下工作正常的代码。然而,最近,代码开始生成以下错误消息,原因不明“系统错误 &H80010105 (-2147417851)”:服务器抛出异常。

Sub SendEmailUsingCOM()

'This macro will open an email session with Lotus Notes,
'add text from the sheet "email" to the body of the email,
'give the email a name and place an email adress.

 'Set up the objects requiered for automation into lotus notes
  Dim Maildb As Object 'The mail database
  Dim UserName As String 'The current users notes name
  Dim MailDbName As String 'The current users notes mail database name
  Dim AttachME As Object 'the attachment richtextfile object
  Dim vToList     As Variant, vCCList As Variant, vBody As Variant
  Dim MailDoc As Object 'the mail document itself
  Dim Session As Object 'The notes session
  Dim EmbedObj As Object 'The embedded object attachment)

  'Open and locate current lotus Notes user
   Set Session = CreateObject("Notes.NotesSession")

   UserName = Session.UserName
   MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"

  Set Maildb = Session.GetDatabase("", MailDbName) 'already open for mail
  If Maildb.IsOpen = True Then
  Else
  Maildb.OpenMail
  End If
  'Set up the new mail document
   Set MailDoc = Maildb.CreateDocument
   vToList = Application.Transpose(Range("S1").Resize(Range("S" & Rows.Count).End(xlUp).Row).Value)
   vCCList = Application.Transpose(Range("B1").Resize(Range("B" & Rows.Count).End(xlUp).Row).Value)
   MailDoc.Form = "Memo"

   MailDoc.Subject = "Demande de Validation"
   MailDoc.Body = [F1].Value
   MailDoc.SavemessageOnSend = True
   MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
   On Error GoTo errorhandler1
   MailDoc.Send 0, vToList

   MsgBox ("Les validations ont été demandées")

   Set MailDoc = Nothing
   Set Maildb = Nothing
   Set Session = Nothing
   Set AttachME = Nothing
   Set EmbedObj1 = Nothing

   errorhandler1:

   Set MailDoc = Nothing
   Set Maildb = Nothing
   Set Session = Nothing
   Set AttachME = Nothing
   Set EmbedObj1 = Nothing

  End Sub

许多用户拥有使用相同脚本的不同 Excel 电子表格,并且此错误仅发生在其中一个上。此外,如果任何其他用户尝试发送电子邮件(再次,勾选任何带有验证者名称的复选框,以便向此人发送电子邮件),不会弹出错误消息。你能帮我解决这个错误吗?

非常感谢。

米格尔

标签: excelvbalotus-notes

解决方案


推荐阅读