Outlook Attachments: It's been years since I made this work, now the years have exacted their toll. (1 Viewer)

Thales750

Formerly Jsanders
Local time
Today, 17:05
Joined
Dec 20, 2007
Messages
2,115
This is the error message.
If you have a link to a place where i can relearn all of the outlook automation, including selecting which calendar to update and pretty much all of it.
I will be thanking you all very much.

1705193409071.png
 

Thales750

Formerly Jsanders
Local time
Today, 17:05
Joined
Dec 20, 2007
Messages
2,115
Just the heads for the curious. I decided to forgo all the reading and let the Chat GPT do that part for me.
The temporary fix was to turn off the

Code:
Set objAttachment = objMail.Attachments.Add("C:\Path\To\Your\File.txt")

That was pretty straight forward, I would have found it. Hell, I even used decent naming conventions.

The GPT found this in about a millionth of a second.

Next I'm going paste my code into it and see what it says about that.

Stand by.
 

Thales750

Formerly Jsanders
Local time
Today, 17:05
Joined
Dec 20, 2007
Messages
2,115
At some point in time a redundancy was created, probably do to accidently pasting a line of code. apparently I never tried to add a an attachment. Mostly because that function in the database was abandoned.

The GPT Found it though.


It looks like there's a redundancy in the attachment section of your code. You are adding the attachment twice, which could lead to the "Array Index Out of Bounds" error. Specifically, you have the line:

vbaCopy code
.Attachments.Add Me.txtAttachment

both before and after the loop that handles multiple attachments. To resolve this issue, you should remove the redundant line outside the loop. Here's the modified section:

Code:
Copy code
'<<<Start Attachment Section
If InStr(Me.txtAttachment, ";") = 0 Then
    .Attachments.Add Me.txtAttachment
Else
    strAttachments = Me.txtAttachment
    ' Parse Attachments and add them to the Attachments collection.
    Do
        .Attachments.Add Left(strAttachments, InStr(strAttachments, ";") - 1)
        strAttachments = Trim(Mid(strAttachments, InStr(strAttachments, ";") + 1))
     Loop While InStr(strAttachments, ";") <> 0
    If Len(strAttachments) > 0 Then .Attachments.Add strAttachments
End If
'<<<End Attachment Section
 

Thales750

Formerly Jsanders
Local time
Today, 17:05
Joined
Dec 20, 2007
Messages
2,115
Next I'm going to ask it to remark this code.

I tried it, it made some small changes. the next step is to get it to remark a completely undocumented procedure, or even a module
 

Thales750

Formerly Jsanders
Local time
Today, 17:05
Joined
Dec 20, 2007
Messages
2,115
The new me. The GPT will be writing all my code in procedures that are not already save in my Code DB.
 

Users who are viewing this thread

Top Bottom