Adding Attachment to Outlook Meeting (1 Viewer)

breakingme10

New member
Local time
Today, 07:43
Joined
Apr 18, 2014
Messages
5
I have found this old post "1237140" (I can't post actual links because my post count is 0, that's the post number in the hyperlink, I normally use accessforums.net for all my problems, but since this is where I found the most relevant albeit unanswered information).
It was never answered and I'm having a similar problem.
I have written a module in VBA that has a subroutine for generating an outlook meeting, it works until I try and add an attachment. The above post says that the attachment property is read-only. Does this mean we cannot an attachments to a meeting through VBA?


My attachment was coming from a text box containing the full file path.

Here is my module and in my form's module, I have set the values for the public variables.

As you can see, I've commented out the attachment portion. As long as I leave it out, the code works great. If I uncomment that or do any other variation of trying to use .attachment at all, it fails. If I try .Attachment.Add I get "Argument Not Optional".

Code:
Option Compare Database

Public oSendTo As String
Public oSubject As String
Public oBody As String
Public oLocation As String
Public oStartDate As String
Public oStartTime As String
Public oEndDate As String
Public oEndTime As String
Public oFullDay As Boolean
Public oAtt As String

Public Sub GenerateMeeting()
On Error GoTo Err_Handler
Dim oOut As New Outlook.Application
Dim oApp As AppointmentItem
Dim oExp As Outlook.Explorer
Set oOut = New Outlook.Application
Set oApp = oOut.CreateItem(olAppointmentItem)
Set oExp = oOut.Session.GetDefaultFolder(olFolderInbox).GetExplorer

With oApp
.OptionalAttendees = "Cal Invites;" & oSendTo
.Recipients.ResolveAll
.Subject = oSubject
.Location = oLocation
.Start = DateValue(oStartDate) & " " & TimeValue(oStartTime)
.End = DateValue(oEndDate) & " " & TimeValue(oEndTime)
.ReminderSet = False
.BusyStatus = olFree
.BodyFormat = olFormatHTML
.Body = oBody
.AllDayEvent = oFullDay
.MeetingStatus = olMeeting
.ResponseRequested = True
'If Not IsNull(oAtt) Then
'    .Attachments.Add = oAtt
'End If
.Display
End With

Exit_Handler:
Set oExp = Nothing
Set oApp = Nothing
Set oOut = Nothing
Exit Sub

Err_Handler:
If Err.Number = 0 Then
Resume Next
Else
MsgBox Err.Number & ": " & Err.Description & vbCrLf & Err.Source, vbOKOnly, "ERROR"
Resume Exit_Handler
End If

End Sub
 

GinaWhipp

AWF VIP
Local time
Today, 08:43
Joined
Jun 21, 2011
Messages
5,901
Hmm, try taking away the =(equal) sign as it not used when sending regular eMail.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:43
Joined
Aug 30, 2003
Messages
36,118
FYI, a string variable can never be Null. Use the Len() function to test it.
 

isladogs

MVP / VIP
Local time
Today, 12:43
Joined
Jan 14, 2017
Messages
18,186
pbaldy is indeed correct.
In my own code (which uses CDO to send mail), I have:

Code:
With Message
        .To = aTo                                   'Set email adress
        .Subject = aSubject                         'Set subject
        .TextBody = aTextBody                       'Set body text
        If Len(aCC) > 0 Then .CC = aCC              'Set copy to if specified
        If Len(aFrom) > 0 Then .From = aFrom        'Set sender address if specified.
        If Len(aPath) > 0 Then .AddAttachment (aPath) 'Attach this file
        .Send    'Send the message
End With

So I think you need one of the following:
If Len(oAtt)>0 Then .Attachments.Add(oAtt)
OR possibly
If Len(oAtt)>0 Then .AddAttachment(oAtt)
 

breakingme10

New member
Local time
Today, 07:43
Joined
Apr 18, 2014
Messages
5
pbaldy is indeed correct.
In my own code (which uses CDO to send mail), I have:

Code:
With Message
        .To = aTo                                   'Set email adress
        .Subject = aSubject                         'Set subject
        .TextBody = aTextBody                       'Set body text
        If Len(aCC) > 0 Then .CC = aCC              'Set copy to if specified
        If Len(aFrom) > 0 Then .From = aFrom        'Set sender address if specified.
        If Len(aPath) > 0 Then .AddAttachment (aPath) 'Attach this file
        .Send    'Send the message
End With
So I think you need one of the following:
If Len(oAtt)>0 Then .Attachments.Add(oAtt)
OR possibly
If Len(oAtt)>0 Then .AddAttachment(oAtt)




Changed it to

Code:
IF Len(oAtt) > 0 then
.Attachments.Add(oAtt)
end if
This doesn't give me any errors, but also doesn't add the attachment.
EDIT:
My code in my form module was checking for null still instead of the len() >0, so this does indeed work!!!!!!
THANK YOU!!!!
 

Users who are viewing this thread

Top Bottom