Solved

VB6 Inserting Outlook Signature using vb6

Posted on 2010-09-01
7
1,555 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
[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
  • 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
Technology Partners: 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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