Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Outlook and Visual Basic 6.0 PDF file

Posted on 2012-03-09
3
Medium Priority
?
949 Views
Last Modified: 2012-06-27
I need to create and send an email using VB 6.0 code through outlook. I have 2 standard message bodies that I have to send out depending on the criteria.
One message body is an overdue message the other is credit message.

So my question how do I use VB to create an outlook message then select one of the message texts to put in the body of the message. Both messages content has to be accessible to the user to edit. Can the 2 messages be contained in somewhere in Outlook, Business Contact Manager or as a Word Doc?

I also need to attach a pdf file.
0
Comment
Question by:Idarac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37704697
Stand By....

Chris
0
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 2000 total points
ID: 37704862
Is this the sort of thing you are after?

Create a folder on your PC called (say) "C:\Messages"

In the folder create two text files, one called "Msg_Credit.txt" and one called "Msg_Overdue.txt"

In these text files the following text appears:
   
  Msg_Credit.txt:
                               This is a CREDIT message with one attachment!
                               <<subject=Credit Message
                               <<attach=c:\Messages\MyPdf1.pdf

Msg_Overdue.txt:

                             This is an Overdue Message with TWO attachmentS
                             <<attach=c:\Messages\MyPdf1.pdf
                             <<attach=c:\Messages\MyPdf2.pdf
                             <<subject=Overdue Message

(Notice that the order of the lines starting with "<<" do not matter)

Now place two PDF files in the "C:\Messages" folder and name them MyPDF1.pdf and MyPDF2.pdf (or change the code to reflect their real names).

Note that the files can reside anywhere but you will need to amend the code to point to their correct location.( I hope this all makes sense to you).

Then place the following code in your VBA Editor and run the macro:
"SendMonthlyMsg".

A pop-up box should appear asking you to whether you want to send an "Overdue" or a "credit" email (it does not matter what you enter, as long as the first letter is either "O" or "C" and it does not matter whether it is upper-case or lower-case).

The best answer is simply "O" or "C" then press enter.

The code will create an email with the text from the appropriate msgfile in the body of the email and with any designated attachments attached.

Please note that at the moment there are two special "command" lines in the msgfile
files (both start with <<).

   "<<attach="  after the "equals" sign type in the full path and filename of the
                       attachment

  "<<subject=" after the "equals" sign type in the words you wish to appear in the "Subject"
                       line of the email.

The code will not attach the attachment if the attachment does not exist. (of course), but it also will not "fall over".

The code follows..........

I hope that will help you on your way...

Cheers
Chris (Australia):

Option Explicit

Public Sub SendMonthlyMsg()
  Dim cType As String
  cType = InputBox("<O>verdue or <C>redit?", "Select Message type")
  
  cType = Left(UCase(Trim(cType)), 1)
  
  Select Case cType
    Case "O"
      SendSpecialMsg "c:\Messages\Msg_Overdue.txt"
    Case "C"
      SendSpecialMsg "c:\Messages\Msg_Credit.txt"
  End Select
End Sub

Private Sub SendSpecialMsg(strMsgFile As String)
  Dim nAttach As Integer
  Dim nAt As Integer
  Dim nFile As Integer
  Dim strFrom As String
  Dim strFile As String
  Dim strSubject As String
  Dim fs As Object
  Dim strLine As String
  Dim strMsg As String
  Dim oMsg As MailItem
  Dim Attachments() As String
  Dim bHasAttachments As Boolean
  Dim oOutlook As outlook.Application
  
  Set fs = CreateObject("Scripting.FileSystemObject")
  ReDim Attachments(0)
  If fs.fileexists(strMsgFile) Then
    nFile = FreeFile
    Open strMsgFile For Input As #nFile
    Line Input #nFile, strLine
    Do While Not EOF(nFile)
      If Left(Trim(strLine), 2) = "<<" Then
        strLine = LCase(Trim(strLine))
        nAt = InStr(strLine, "=")
        Select Case Mid(strLine, 3, nAt - 3)
          Case "attach"
            ReDim Preserve Attachments(UBound(Attachments) + 1)
            strFile = Trim(Mid(strLine, nAt + 1))
            If fs.fileexists(strFile) Then
              bHasAttachments = True
              Attachments(UBound(Attachments)) = strFile
            End If
          Case "subject"
            strSubject = Trim(Mid(strLine, nAt + 1))
        End Select
      Else
        strMsg = strMsg + strLine + vbCrLf
      End If
      Line Input #nFile, strLine
    Loop
    Close #nFile
    If Len(strMsg) > 0 Then
      Set oOutlook = New outlook.Application
      Set oMsg = oOutlook.CreateItem(olMailItem)
      oMsg.Body = strMsg
      If bHasAttachments Then
        For nAttach = 1 To UBound(Attachments)
          oMsg.Attachments.add Attachments(nAttach)
        Next
      End If
      If Len(strSubject) > 0 Then
        oMsg.Subject = strSubject
      End If
    End If
  End If
  oMsg.Display vbModal
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Idarac
ID: 37705379
Excellent answer Chris thanx over there in Aussi land.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question