Excel-Word-Outlook merge controlled by VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tequilaman
    New Member
    • Oct 2007
    • 43

    Excel-Word-Outlook merge controlled by VBA

    Here comes are real tricky one:

    I'm approaching a project that seems impossible at first sight. I want to merge an Excel list where I find who will get which kind of information by email, with a word based document (can be an Outlook draft as well) and use the email adress form the Excel list as receipant of one email each. The emails will be different for every adress! - There might be attachments as well, but the import routine for that is not part of the problem, only that I must implement this existing code (e.g. call it as a prog or converted function).

    Has anybody expirience with the Outlook link? - I can control Excel and Word rather easily, but the Outlook connection is kind of a white dot in my planning right now.

    Are there any Outlook connection codes available that I can find somewhere? - Though I solved my last questions before an answer was ther, this time I guess it might take more than just some hours to get it done....
  • Tequilaman
    New Member
    • Oct 2007
    • 43

    #2
    By the way, I need to send some email (possibly all, but not necessary) in HTML too. - I want to use a simple 0/1 column for the identification what should be HTML

    Comment

    • BlackMustard
      New Member
      • Aug 2007
      • 88

      #3
      Originally posted by Tequilaman
      By the way, I need to send some email (possibly all, but not necessary) in HTML too. - I want to use a simple 0/1 column for the identification what should be HTML
      I do similar things with macros written from Outlooks VBA editor (open it by pressing Alt+F11 when in Outlook). From there I control Word and Excel as well as outlook by the three very simple objects declared and initiated below. (Note that if this is to work, you have to import all the relevant class libraries to your project.)

      [code=vb]
      Dim appOutlook As Outlook.Applica tion
      Dim appWord As Word.Applicatio n
      Dim appExcel As Excel.Applicati on

      Sub InitRoutine()
      Set appOutlook = New Outlook.Applica tion
      Set appWord = New Word.Applicatio n
      Set appExcel = New Excel.Applicati on
      End Sub[/code]

      you can then for example start writing a new email, in html or plain text, and insert a string in the body by using the following commands:

      Code:
      Dim objMail as New MailItem
      If blnUseHTML Then ' blnUseHTML contains info on whether to use html
          objMail.HTMLBody = strBody ' strBody contains the message
      Else
          objMail.Body = strBody
      End If
      I personally prefer to use HTML and store it in a txt file.

      Comment

      • Tequilaman
        New Member
        • Oct 2007
        • 43

        #4
        Well, I am nearly an analphaHTML. A friend of mine has written the converter I use from and modify in VBA. In these cases I always start from Word.

        To start it off from Outlook might really make it easier as I just saw. I'll try it as soon as I have managed to adjust the HTML templates.

        Comment

        Working...