Solved

VB6 Inserting Outlook Signature using vb6

Posted on 2010-09-01
7
1,532 Views
Last Modified: 2013-11-25
I use the following code to send an email
Public Sub SendEmail(iRecipient, iSubject As String, iAttach As String, iBody As String)
Dim myOlApp As Outlook.Application
Dim myItem As MailItem
Dim myAttachments As Attachments
Dim MyItemSize As Long
Dim sUserName As String
Dim oInsp As Outlook.Inspector

    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.CreateItem(olMailItem)
    Set myAttachments = myItem.Attachments
    Set oInsp = myItem.GetInspector
    myItem.Recipients.Add iRecipient
    myItem.Subject = iSubject
    myItem.Attachments.Add iAttach
    myItem.ReadReceiptRequested = True
'    myItem.Body = iBody
    myItem.Display
End Sub

This code displays the correct default signature. As soon as I uncomment the line 'myItem.Body = iBody' it deletes the signature and only shows the body text- Any Ideas

0
Comment
Question by:Martin-Swannie
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33579024
did u check what was passed into iBody? Could that text have the signature added in?
instead of commenting out, what if you passed in a empty string, does that still produce a signature?
0
 

Author Comment

by:Martin-Swannie
ID: 33579288
I will try passing an empty string and let u know
0
 

Author Comment

by:Martin-Swannie
ID: 33579306
Passing an empty string also deletes the signature
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 65

Expert Comment

by:rockiroads
ID: 33579480
can you check the contents of ibody? maybe that string contains the signature
0
 

Author Comment

by:Martin-Swannie
ID: 33579973
ibody only contains text which the user enters in a text box. Under the text I want to display the Default Outlook Signature. If I exclude the ibody then the Signature displays correctly. As soon as ibody is added it deletes the Signature and only displays the ibody text. i.e. it does not insert iBody it seems to overwrite the Signature
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33580574
So you have definitely inspected the text passed into iBody? (by the way, it should really read sBody as i refers to a numeric).

From what I gather, outlook automation does not include signature by default. Only way I knew how to add a signature when I used outlook auto is to open the signature file and add in the contents into iBody.
0
 

Accepted Solution

by:
Martin-Swannie earned 0 total points
ID: 33585160
I have solved the problem by not adding the line "myItem.Body = iBody" and replaced it with the following using sendkeys. It works perfectly and the default signature is displayed. The iBody string must have "," between the text which are converted to {enter}

Public Sub SendEmail(iRecipient, iSubject As String, iAttach As String, iBody As String)
Dim tStr As String
Dim myOlApp As Outlook.Application
Dim myItem As MailItem
Dim myAttachments As Attachments
Dim MyItemSize As Long
Dim sUserName As String
Dim oInsp As Outlook.Inspector

    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.CreateItem(olMailItem)
    Set myAttachments = myItem.Attachments
    Set oInsp = myItem.GetInspector
    If iRecipient <> "" Then
        myItem.Recipients.Add iRecipient
    End If
    myItem.Subject = iSubject
    If Right(iAttach, 1) <> "\" Then
        myItem.Attachments.Add iAttach
    End If
    myItem.ReadReceiptRequested = True
    myItem.Display
   
    Dim iTxt As String
    Dim iLeft As Integer
    tStr = iBody
    Do While True
        iLeft = InStr(1, tStr, ",", vbTextCompare)
        If iLeft > 0 Then
            iTxt = Left(tStr, iLeft - 1)
            SendKeys iTxt, True
            SendKeys "{enter}", True
            tStr = Right(tStr, Len(tStr) - iLeft)
        Else
            SendKeys tStr, True
            SendKeys "{enter}", True
            Exit Do
        End If
    Loop
End Sub
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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