Link to home
Start Free TrialLog in
Avatar of amfierst
amfierstFlag for United States of America

asked on

Icon in Lotus Notes appearing as gray icon

I have VBA code that sends an email with an attachment when executed.  The attachment is an excel spreadsheet.  When the email is received, however, a gray icon appears in the email instead of the excel icon.  Whey I try to process this attachment through vba code, the attachment is not viewed as a RICHTEXT, but rather as TEXT, which is preventing me from detaching it via VBA.  How do I get the icon to display as an Excel icon?

My code for attaching the email and sending it is shown below:

  ' Declare Variables for file and macro setup

    Dim UserName, MailDbName, MailMessage As String
    Dim Maildb, MailDoc, Session, EmbedObj1, AttachME As Object
    Dim RichTextBody, RichTextAttachment As Object
   
' Open and locate current LOTUS NOTES User

    Set Session = CreateObject("Notes.NotesSession")
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    Set Maildb = Session.GETDATABASE("", MailDbName)
    If Maildb.IsOpen = True Then
    Else
        Maildb.OPENMAIL
    End If

    Set MailDoc = Maildb.CreateDocument
    MailDoc.Form = "Memo"
    Recipient = "email id"
    MailDoc.SendTo = Recipient
    MailDoc.Subject = "PILOT: Software Audit Results"
    MailMessage = "Software audit results attached."
    Set RichTextBody = MailDoc.CREATERICHTEXTITEM("Body")

    MailDoc.Body = MailMessage
    MailDoc.SAVEMESSAGEONSEND = True
   
    If Attachment1 <> "" Then
        Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
        Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment1, "Attachment")

    End If
   
    MailDoc.PostedDate = Now()
    On Error GoTo ErrorHandler1
    MailDoc.Send 0, Recipient

    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set Session = Nothing
    Set EmbedObj1 = Nothing
    Set AttachME = Nothing

Avatar of amfierst
amfierst
Flag of United States of America image

ASKER

Another thing I noticed too.  When I view the attachment properties in Lotus Notes, it appears as though the attachment has been compressed.  I wonder if this has anything to do with it.  The size in the attachment property says:  Length:  67 Kbytes (66.9%).
several things:
-I believe attaching files programmatically never (at least until 7.x version of LN) displays the application icon.
-why would you create the "attachment" field? with Notes you can embedd the attachment directly into the body field of the mail: just add a newline to the richtext (Body) and then embedd the object
try to change the line like this:

Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment1)
where Attachment1 is the name (with path) to your excel.

How do I get the icon to display as an Excel icon?=> As I remember you get a real excel icon if on the machine where run your code is INSTALLED AND the extension of the file is linked with Excel

Compression is not a problem
Hi ManRaanana,

Thanks for your suggestions.  I tried everything you suggested and it didn't make a difference :-(   I'm still not getting the attachment as an Exce icon :-(
double click on it open it in EXCEL?
where run the code ? on a server or on a client ?
Manu,

Yes, it opens in Excel when I double-click it, but when I try to process (detach) the file in VBA, it doesn't process as an excel attachment (richtext).  That's really the issue.  The code runs on a client machine.  Thanks again for your input.

Anne Marie
Anne Marie. Are we having another issue know?

The last problem was not at all connected to the missing excel icon. And would bet 100$ that you can't(without calling C-API) attach with the proper icon from LotusScript

I am almost the expert reg attachments
Hi Pinky,

No, not another issue.  Same issue.  Attaching an excel file in VBA and sending an email as depicted in my code in my original post.  When the email is received, the attachment is a gray icon instead of a excel icon.  The reason I need it attached as an excel icon is so that I can detach the attachment with vba.  When I try to detach the gray icon in vba, it won't because it's not an excel icon (which is rich text format).  Same problem...  I'm not using Lutus Script, by the way, I'm using VBA in Excel/Access.

Thanks,

Anne Marie
icon well I'm pretty sure that with MIME it works:

      Dim body As NotesMIMEEntity, MimeChild As NotesMimeEntity
      Set body = maildoc.CreateMIMEEntity
      Set MimeChild = body.CreateChildEntity
Call MimeChild.SetContentFromBytes(excelStream,   _
      |application/excel; name="| + attachmentName + |"|, ENC_IDENTITY_BINARY)

where excelStream is a notesstream reading your Excel
not so simple to perform I agree but HELP is OK
ipinky, if it works you send me 100$ ? just kidding...

concerning " try to process (detach) the file in VBA, it doesn't process as an excel attachment (richtext). " may you post your vba code,
your also wrote"the attachment is not viewed as a RICHTEXT, but rather as TEXT"
do you mean the body ?

'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
  Forall o In rtitem.EmbeddedObjects
    If ( o.Type = EMBED_ATTACHMENT ) _
    And ( o.FileSize > MAX ) Then
      fileCount = fileCount + 1
      Call o.ExtractFile _
      ( "c:\reports\newfile" & Cstr(fileCount) )
      Call o.Remove
      Call doc.Save( True, True )
    End If
  End Forall
End If
Manu,

I shall try processing it this way and will let you know...thanks.  What I meant when I said the attachment isn't interpretted as RICHTEXT is that in my code below (which is trying to detach the attachment from the email), the TYPE field is '2', which signifies TEXT, as opposed to '1', which signifies RICHTEXT.  When the gray icon is an actual excel icon, the TYPE is '2', which is what I need it to be for the code to work.  I tried changing the if statement below to process a TEXT attachment, but the code won't work.

Code to detach an attachment from an email in VBA:

sPathToSave = "Destination Path"
Dim View As Object 'New Domino.NotesView
Dim nDoc As Object 'Domino.NotesDocument
Const RICHTEXT = 1
Const EMBED_ATTACHMENT = 1454
Set s = CreateObject("Notes.Notessession")    'create notes session
    Set db = s.GETDATABASE("", "")   'set db to database not yet named
    Call db.openmail
Set View = db.GetView("($Inbox)")
Set nDoc = View.GetFirstDocument
Dim itm As Variant
While Not (nDoc Is Nothing)
    If nDoc.HasEmbedded Then
        Set itm = nDoc.GetFirstItem("Body")
        If itm.Type = RICHTEXT Then
            Dim attch As Variant
            For Each attch In itm.EmbeddedObjects
                If (attch.Type = EMBED_ATTACHMENT) Then
                    attch.ExtractFile sPathToSave & attch.Name
                End If
            Next
        End If
    ' Following code commented is used to delete mails after
    ' attachments were saved to disk.
        'Set nDoc2Remove = nDoc
    End If
    Set nDoc = View.GetNextDocument(nDoc)
    ' Following code commented is used to delete mails after
    ' attachments were saved to disk
    'If Not (nDoc2Remove Is Nothing) Then
    '    nDoc2Remove.Remove (True)
    '    Set nDoc2Remove = Nothing
    'End If
Wend
End Sub
Manu,
  I just found this code in experts exchange that seems to do what you're suggesting.  It does create open up a Lotus Note with the attachment as an excel icon (which is good!!!).  Would you know what code I need to add to automatically send this note instead of having to click the send button manually?

Sub Test()
 
  Dim html As String
  Dim attachments(0) As String, imageFiles(0) As String, imageTypes(0) As String, imageTags(0) As String
  html = "<div style='font-size: 10pt; font-family: Arial, Helvetica, sans-serif; font-weight: bold;'><img src='cid:any_jpeg.jpg'>This is a test!</div>"
  attachments(0) = "c:\My Documents\Software Audit Tool\Software_Audit v0.2.xls"
  Call ComposeMemo("afierst@us.ibm.com", "Test from Excel", html, attachments)
 
End Sub
 
Sub ComposeMemo(sendto As String, ByVal subject As String, ByVal html As String, attachments() As String)
 
  Dim sess As Object, db As Object, doc As Object, stream As Object, ws As Object, uidoc As Object
  Dim mimeBody As Object, mimeHtml As Object, mimeFile As Object, mimeImage As Object, mimeHeader As Object
  Dim i As Integer
  Dim convertMime As Boolean
  Const ENC_QUOTED_PRINTABLE = 1726
  Const ENC_IDENTITY_8BIT = 1729
  Const EMBED_ATTACHMENT = 1454
 
  ' Create an email doc
  Set sess = CreateObject("Notes.NotesSession")
  Set ws = CreateObject("Notes.NotesUiWorkspace")
  Set db = sess.GetDatabase("", "")
  Call db.OpenMail
  Set doc = db.CreateDocument()
  Call doc.ReplaceItemValue("Form", "Memo")
 
  ' add the body as a mime html part
  convertMime = sess.convertMime
  sess.convertMime = False
  Set stream = sess.CreateStream()
  stream.WriteText (html & "<br><br>")
  Set mimeBody = doc.CreateMIMEEntity("Body")
  Set mimeHtml = mimeBody.CreateChildEntity()
  Call mimeHtml.SetContentFromText(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
  Call stream.Close
 
  ' add file attachments
  For i = 0 To UBound(attachments)
    Set mimeFile = mimeBody.CreateChildEntity()
    Set mimeHeader = mimeFile.CreateHeader("Content-Transfer-Encoding")
    Call mimeHeader.SetHeaderVal("binary")
    Set mimeHeader = mimeFile.CreateHeader("Content-Disposition")
    Call mimeHeader.SetHeaderVal("attachment; filename=" & attachments(i))
    Call stream.Open(attachments(i), "binary")
    Call mimeFile.SetContentFromBytes(stream, "text/plain", ENC_NONE)
    Call mimeFile.EncodeContent(ENC_IDENTITY_8BIT)
    Call stream.Close
  Next
 
  sess.convertMime = convertMime
  Call doc.CloseMIMEEntities(True, "Body")
  Call doc.Save(True, False)
  Set uidoc = ws.EditDocument(True, doc)
  Call doc.Remove(True)
  ' Exit Sub ' if you don't need the user's signature, you can exit here, otherwise...
  Call uidoc.GotoField("Body")
  Call uidoc.SelectAll
  Call uidoc.Copy
  uidoc.Document.SaveOptions = "0"
  uidoc.Document.MailOptions = "0"
  Call uidoc.Close
 
  ' compose a new memo and paste the body.
  Set uidoc = ws.ComposeDocument(db.Server, db.FilePath, "Memo")
  Call uidoc.FieldSetText("EnterSendTo", sendto)
  Call uidoc.FieldSetText("Subject", subject)
  Call uidoc.GotoField("Body")
  Call uidoc.Paste
 
End Sub
I figured out how to send the email....just added the following two lines to my code and it worked!  Thanks all for your help!

  Call uidoc.Send(Now)
  Call uidoc.Close
ASKER CERTIFIED SOLUTION
Avatar of Emmanuel Gleizer
Emmanuel Gleizer
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Manu...I'll change that so it is saved!