+ Reply to Thread
Results 1 to 3 of 3

Controlling Outlook (body of email) via excel

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2009
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    1

    Controlling Outlook (body of email) via excel

    HI there, I have been working on this for awhile and although I have gotten help via other methods, none of them seem to work in the manner I would like for it to do so. Other methods include, looping, HTML and formatting the string b4 it is imported into

    SO this is what I have done, I have taken recorder in outlook and supplied the body of the email with data seperated by commas. Then i recorded the next steps with recorder selected the tools and then tables within outlook. I am trying to make it where excel can control this code that I recorded in outlook. I assume i have to define an object or something but i am missing a step. anyone have any thoughts? thanks so very much in advance.

    Ooops, also the code for creating the email was created by someone else, and I have been using it for years for converting a range into HTML and plascing in body of emails...but now, I cant use html

    #
    Sub email()
    
    
    Dim TodayFile
    Dim FileDate
    
    'Sends a specified range to a Outlook message and retains Excel formatting
    
    'References needed :
    'Microsoft Outlook Object Library := msoutl9olb
    'Microsoft Scripting Runtime      := SCRRUN.DLL
    
    'Dimension variables
    '// ie. if Ol not installed then we need to Late bind & define as Obj
    '// Use Late binding > Outlook.Application > olMail As Outlook.MailItem
    '// Plus define olmailItem
    Dim olApp As Object, olMail, olMailItem
    Dim FSObj As Scripting.FileSystemObject, TStream As Scripting.TextStream
    Dim rngeSend As Range, strHTMLBody As String
    
    
    'Select the range to be sent
    Set rngeSend = Range("B3:J29")
    
    'Now create the HTML file
    '// Changes by IFM
    '// changed "C:\temp\sht.htm" to Dynamically get Sys Temp Dir
    '// To cover the instance where Tmp Dir is NOT @ C:\
    Dim SysTmp As String
    SysTmp = TmpFolderLocation
    ActiveWorkbook.PublishObjects.Add(xlSourceRange, SysTmp & "\sht.htm", _
        rngeSend.Parent.Name, rngeSend.Address, xlHtmlStatic).Publish True
    
    'Create an instance of Outlook (or use existing instance if it already exists
    Set olApp = CreateObject("Outlook.Application")
    
    'Create a mail item
    Set olMail = olApp.CreateItem(olMailItem)
    
    'Open the HTML file using the FilesystemObject into a TextStream object
    Set FSObj = New Scripting.FileSystemObject
    Set TStream = FSObj.OpenTextFile(SysTmp & "\sht.htm", ForReading)
    
    'Now set the HTMLBody property of the message to the text contained in the TextStream object
    strHTMLBody = TStream.ReadAll
    
    Worksheets("SumPasteTab").Activate
    TodayFile = Range("Q27").Value
    FileDate = Range("N2").Value
    
    attachmnt = "S:\USA-HOUSTON\CPDS\GT FAMM\IctsOnline\Global Trading\Risk Control\Daily GM Tracking\test\" & TodayFile & ".pdf"
    
    
    
    'utilization
    U_CSAT = Range("D15").Value
    U_PSAT = Range("D16").Value
    U_LSAT = Range("D17").Value
    U_SOG = Range("D18").Value
    U_TTL = Range("D19").Value
    
    'flat
    F_CSAT = Range("F15").Value
    F_PSAT = Range("F16").Value
    F_LSAT = Range("F17").Value
    F_SOG = Range("F18").Value
    F_TTL = Range("F19").Value
    
    'utilization
    FU_CSAT = Range("G15").Value
    FU_PSAT = Range("G16").Value
    FU_LSAT = Range("G17").Value
    FU_SOG = Range("G18").Value
    FU_TTL = Range("G19").Value
    
    
    
    strbody = FU_CSAT & "," & FU_PSAT & "," & FU_TTL & Chr(13) & _
    F_CSAT & "," & F_PSAT & "," & F_TTL & Chr(13) & _
    U_CSAT & "," & U_PSAT & "," & U_TTL & Chr(13)
    
    
    With olMail
        .To = "hlcu@chevron.com"
        .Subject = " Global DPR  " & Format(Date, "mm-dd-yyyy")
        .Body = str
        '.HTMLBody = strHTMLBody
        '.Attachments.Add (attachmnt)
        .Display
        '.Send
    End With
    
    
     '   Selection.HomeKey Unit:=wdStory
      '  Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
      '  Selection.ConvertToTable Separator:=wdSeparateByCommas, NumColumns:=3, _
       '     NumRows:=3, AutoFitBehavior:=wdAutoFitFixed
       '     With Selection.Tables(1)
        '        If .Style <> "Table Grid" Then
          '          .Style = "Table Grid"
           '     End If
            '    .ApplyStyleHeadingRows = True
            '    .ApplyStyleLastRow = True
             '   .ApplyStyleFirstColumn = True
             '   .ApplyStyleLastColumn = True
          '  End With
    
    
         
    End Sub
    
    Function TmpFolderLocation() As String
    Dim Fso, TFolder
    
    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set TFolder = Fso.getSpecialFolder(2)
    
    TmpFolderLocation = TFolder.Path
    
    Set Fso = Nothing
    Set TFolder = Nothing
    
    End Function
    #
    Last edited by hlatigo; 02-23-2009 at 12:43 AM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Controlling Outlook (body of email) via excel

    Hi HLatigo, and welcome to the forum.

    Please review the Forum Rules (link in my signature), specifically regarding the use of CODE tags.

    Thank you.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Controlling Outlook (body of email) via excel

    Hello hlatigo,

    Welcome to the Forum and thanks for adding the code tags.

    I could help you if I understood what is you want to achieve. Why can't you use HTML now? How do you want this table to appear in the email body? Can you provide a sample workbook for review?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1