Consulting

Results 1 to 2 of 2

Thread: Passing a MailItem to Sub

  1. #1

    Solved: Passing a MailItem to Sub

    Hi, this is my first post

    I am somewhat new to VBA so hope this isn't too basic a question but I have spent lots of time learning things searching this site and Google but still can't find the answer to this question:

    I would like to pass a MailItem to a sub so I can modify its contents. I keep getting a "Run-time error '424': Object required" My call is in here:

    [vba]
    Dim copyFromEmail As outlook.MailItem
    Dim newEmail As outlook.MailItem

    For Each copyFromEmail In emailCollection
    Set newEmail = Application.CreateItem(olMailItem)
    Set newEmail = copyFromEmail.copy

    newEmail.UnRead = True
    newEmail.Move clientLocation

    'Change out template data with Implementation Data
    replaceTemplateData (newEmail) ' ***** Error occurs here ********
    Next copyFromEmail
    [/vba]
    And my subroutine setup is like this:
    [vba]Public Sub replaceTemplateData(email As outlook.MailItem)

    End Sub[/vba]
    Any help would be greatly appreciated,
    Reuben

    ps - ohhh, my loop takes emails stored in a collection and "saves" them to a folder in Outlook. It seems like a clunky way to do this so if anyone has suggestions I'm open to those as well. Thanks!!
    Last edited by ImagineTNT; 11-14-2008 at 12:15 PM.

  2. #2
    OK, I realized what I was doing wrong. I needed to call replaceTemplateData and pass the parameter WITHOUT parentheses.

Posting Permissions

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