Ich habe eine Unterkomponente in einem Formular, mit der Benutzer Fehler melden und Verbesserungen am Formular vorschlagen können. Ich habe es so gut wie fertig, aber es kommt immer wieder zu Problemen beim Hinzufügen von Anhängen.Hinzufügen von Listbox-Elementen als E-Mail-Anhänge
Sub Submit()
Dim OutApp As Object
Dim OutMail As Object
Dim Item
Dim STR As String, AdminOnly As String, TruncBox As String, STRAttachments As String
For Each cCont In Me.MultiPage1.SelectedItem.Controls
Select Case TypeName(cCont)
Case "TextBox"
If cCont.value = "Please enter a short description here." Or _
cCont.value = "Please enter a short description here." Then
MsgBox ("Please enter all information.")
Exit Sub
ElseIf cCont.value = "" Then
MsgBox ("Please enter all information.")
Exit Sub
End If
Case "ComboBox"
If cCont.value = "" Then
MsgBox ("Please enter all information.")
Exit Sub
ElseIf InStr(cCont.value, "Report") Then
TruncBox = "BUG"
Else
TruncBox = "SUGGESTION"
End If
End Select
Next
STR = "{email address redacted}"
If RecipientsListBox.ListCount = 0 Then
AdminOnly = MsgBox("Only admin will receive updates!", _
vbOKCancel + vbExclamation, "No Users on Watch List")
If AdminOnly = vbCancel Then
Exit Sub
Else
STR = STR
End If
Else
For Each Item In RecipientsListBox.List
STR = STR & ";" & Item
Next Item
End If
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = STR
Call .Recipients.resolveall
.Subject = TruncBox & ": " & ActiveWorkbook.Name & ": " & ShortDescriptionTextBox
.Body = LongDescriptionTextBox
If AttachmentsListBox.ListCount = 0 Then
Else
For Each Item In AttachmentsListBox.List
STRAttachments = Item
.Attachments.Add STRAttachments
Next Item
End If
'.Send 'Or use Display
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
Ich habe bei Schleifen zu jedem Punkt der AttachmentsListBox
Kontrolle durch verschiedene Versuche laufen und bereit, um Hilfe zu bitten. Dieser letzte Versuch ergab Run-time error '94': Invalid use of Null
mit der Zeile STRAttachments = Item
, die im markierten Abschnitt null zurückgibt. Wenn ich mir ansehe, was ich bereits habe und im Vergleich zu anderen Suchen im Internet, verstehe ich das nicht. Ich habe die Variante Item
zu STR
in der Zeile STR = STR & ";" & Item
oben zurückgegeben, und ich habe andere Beispiele von Strings gesehen, die als Anhänge zurückgegeben werden. Was vermisse ich?
vergessen zu erwähnen 'cCont' ist öffentlich erklärt Kontrolle. – dubyarly