Run time 91 error in VBA code

adubberegreen

New Member
Joined
Mar 24, 2014
Messages
1
Hello. I'm a novice when it comes to VBA coding, and I have a question about why I might be getting a run time 91 error with the following code, specifically the argument reading "Else MailDoc.Body = DiscMarker".

Any help that can be provided will be greatly appreciated.

___________________________________________________________________________________________________________________

Function ComposeEmailInOutlook(Optional ByVal SendToArray As Variant, _
Optional ByVal Subject As Variant, _
Optional ByVal PathToBody As Variant, _
Optional ByVal PathToDisclaimer As Variant, _
Optional ByVal CopyToArray As Variant, _
Optional ByVal BlindCopyToArray As Variant, _
Optional ByVal AttachmentFileArray As Variant) As Boolean


'On Error GoTo ErrHandler


Dim I As Long
Dim Msg As String
Dim OutApp As Object
Dim Outmail As Object
Dim olNameSpace As Object
Dim oEmail As Object
Dim MailDoc As Object
Dim AttachME As Object
Dim EmbedObj As Object
Dim Workspace As Object
Dim UIDoc As Object
Dim WordApp As Object
Dim WordDoc As Object
Dim BodyMarker As String
Dim DiscMarker As String


'Create an Outlook Session
Set OutApp = CreateObject("Outlook.application")
Set Outmail = OutApp.Createitem(0)


'Get the Outlook UserName
Set olNameSpace = OutApp.GetNamespace("MAPI")
MsgBox olNameSpace.CurrentUser

'Try using of already open Outlook Application
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")

' If Outlook Application was not active then create it
If Err Then Set OutApp = CreateObject("Outlook.Application")
On Error GoTo 0


'Create New Email
Set oEmail = OutApp.Createitem(0)

'Populate the recipients
If Not VBA.IsMissing(SendToArray) Then MailDoc.SendTo = SendToArray
If Not VBA.IsMissing(CopyToArray) Then MailDoc.CopyTo = CopyToArray
If Not VBA.IsMissing(BlindCopyToArray) Then MailDoc.BlindCopyTo = BlindCopyToArray


'Populate the Subject & Body of the Email
If Not VBA.IsMissing(Subject) Then MailDoc.Subject = Subject
If Not VBA.IsMissing(PathToBody) Then MailDoc.Body = BodyMarker & vbCrLf & vbCrLf & DiscMarker Else MailDoc.Body = DiscMarker
MailDoc.Save True, False
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top