Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 Inserting Outlook Signature using vb6

Posted on 2010-09-01
7
Medium Priority
?
1,605 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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.
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…
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…
Suggested Courses

722 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