Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB6 Inserting Outlook Signature using vb6

Posted on 2010-09-01
7
Medium Priority
?
1,645 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

916 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