+ Reply to Thread
Results 1 to 4 of 4

Copying a VBA mail object whilst preserving original

  1. #1
    Registered User
    Join Date
    01-04-2013
    Location
    United Kingdom
    MS-Off Ver
    Office 2013
    Posts
    40

    Question Copying a VBA mail object whilst preserving original

    Hi all,

    I am creating a program to send emails with several attachments out to a database of contacts. I first set up a mail object, and define some parameters and add an initial attachment, shown below.

    Please Login or Register  to view this content.
    I then use a For loop to go through each contact to then set more parameters of the email, such as the To field and to add further, personalised attachments, but I want to preserve the above settings as a fresh email to start with on each loop. So naively I thought I could just copy the mail object, like below....

    Please Login or Register  to view this content.
    But if I edit temp_CDO_Mail, it also changes CDO_Mail, as I now realise that temp_CDO_Mail is just a pointer, rather than a distinct copy. I don't really want to just redefine CDO_Mail on each loop, because I want the code to be as fast as possible and I want to limit adding in that first attachment. So what are my options for literally copying CDO_mail into a distinct (non pointer) object?

    Any searching I've done just talks about creating your own classes and cloning items/properties. But not sure this really applies with an inbuilt mail object? Can anyone help?

    Many thanks,

    Chris

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    11,138

    Re: Copying a VBA mail object whilst preserving original

    Quick question...Is Outlook not an option...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    01-04-2013
    Location
    United Kingdom
    MS-Off Ver
    Office 2013
    Posts
    40

    Re: Copying a VBA mail object whilst preserving original

    No not really, I have a whole system built in VBA and Excel that accesses other software (Capita's SIMS in this case), and that's used to extract the contact database. I dabbled at the very start with using Outlook as an object to send emails but it was too cumbersome with pop ups and security alerts, the CDO mail object gave me much greater freedom, and the user does not then need to have outlook running.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    11,138

    Re: Copying a VBA mail object whilst preserving original

    No need for outlook to be running...Anyway, why not upload a sample file and explain in detail what you want to achieve...Step by step...I am very certain someone will be able to provide a clean solution...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Preserving link to an Excel sheet when running a mail merge
    By Grilleman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2019, 11:28 AM
  2. [SOLVED] Temporary highlight row of active cell whilst retaining original formatting
    By kmis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2014, 02:58 AM
  3. [SOLVED] Create multiple rows from cell value whilst preserving other cell values
    By Kjellis85 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 11-15-2013, 03:47 AM
  4. How can one copy cells while preserving the original format?
    By iustin.mihailescu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2013, 12:30 PM
  5. [SOLVED] Combining Contents of two cells whilst preserving text coloring
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2013, 12:20 AM
  6. Replies: 4
    Last Post: 01-04-2013, 01:38 PM
  7. mail merge from excel whilst maintaining format
    By mania112 in forum Excel General
    Replies: 5
    Last Post: 11-04-2009, 05:30 PM

Tags for this Thread

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