Consulting

Results 1 to 3 of 3

Thread: Function Module (Display and Send)

  1. #1

    Function Module (Display and Send)

    HI,

    Thank you all for your valuable inputs, I wanted to include one command in below programme, when I enter “Display” in my input box, mail should generate and display, if I give command as “Send” email should automatically send without popping up, everything works fine if I enter “.Display” and “.send” in the place where I keyed in Myinput, but am not able to use this with input box, can anyone suggest me where am I going wrong.

    Thanks

    [VBA]
    Function GVR_Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
    StrSubject As String, StrBody As String, Send As Boolean)
    Dim OutApp As Object
    Dim OutMail As Object
    Dim MyInput
    MyInput = InputBox("Enter the Mode of communication (Display or Send)")

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
    .To = StrTo
    .CC = ""
    .BCC = ""
    .Subject = StrSubject
    .Body = StrBody
    .Attachments.Add FileNamePDF
    If Send = True Then
    .Send
    Else
    .MyInput
    End If
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    End Function
    [/VBA]

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Why do you need to show a MsgBox? The code that calls the Function can set the Send boolean value as needed.

    [vba]Function GVR_Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
    StrSubject As String, StrBody As String, Send As Boolean)

    Dim
    OutApp As Object

    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set
    OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
    .To = StrTo

    .CC = ""
    .BCC = ""
    .Subject = StrSubject
    .Body = StrBody

    .Attachments.Add FileNamePDF

    If Send Then
    .Send Else
    .Display
    End If
    End With
    On Error Goto 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    End Function [/vba]

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Is this the same problem as in
    http://www.vbaexpress.com/forum/showthread.php?t=39614 ?

    Please don't start multiple threads on the same problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •