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
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