+ Reply to Thread
Results 1 to 11 of 11

Macro to delete email as per string or cell data

  1. #1
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Question Macro to delete email as per string or cell data

    Good Morning

    Is there a way to have an excel macro delete an email/s from a particular sender, I know you can use this in outlook but I need it to be done via excel if possible.

    I have tried lots of variants I have seen online but none of them work.

    I'm using excel & outlook 2010

    Thanks Dave

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Macro to delete email as per string or cell data

    If it can be done in Outlook (and it can) then it's a simple matter to do it in Excel. You just need to create/set a reference to Outlook in the code and then a few minor changes.

    As you 'have tried lots of variants' then post one or 2 of the samples you did try. There's no need to start afresh when there's existing code.

  3. #3
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Macro to delete email as per string or cell data

    Hi Cytop

    here's what I tried

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Macro to delete email as per string or cell data

    also having the option to delete email as per subject would be great

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Macro to delete email as per string or cell data

    First question is are you going to use Early Binding or Late Binding?

    If you don't know what these are then you really should go search "early late binding vba" and read, then decide which to use...

    Also, the SenderName may not contain a full email address, but a 'friendly' name, if available and there usually is one. Would it be an idea to check the actual Sender email address?

    Last obvious things:

    There's an error on the line
    Please Login or Register  to view this content.
    Easy enough to spot once you know it's there but you should consider using the 'Option Explicit' compiler directive to catch that when the code is compiled.

    You might like to use the 'Option Compare Text' compiler directive to remove the need to convert text to upper/lower case when comparing.

  6. #6
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Macro to delete email as per string or cell data

    Hi Cytop

    Right I believe Early Binding is whats needed, are you able to provide the appropriate code to achieve the above if at all possible, with subject search as well maybe.

    no worries if not but it would be a big help :-)

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Macro to delete email as per string or cell data

    I would prefer you understand the implications of using Early Binding but it is simply a matter of adding a reference to the Outlook using the Tools/References menu and change the CreateObject line to


    Please Login or Register  to view this content.
    The Subject search can wait until this is working...

  8. #8
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Macro to delete email as per string or cell data

    Hi Ctop

    Maybe my original
    Last edited by dave1983; 01-24-2017 at 10:25 AM.

  9. #9
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Macro to delete email as per string or cell data

    Hi Ctop

    maybe my original understanding was flawed Ill look at some more articles, can I check then that the suggestion you made only needs to be done within excel as I realise I missed a vital bit of information stating that the other macro I have sends an email to a recipient with an attachment, saves it and at that point I then want a macro to delete the email in the other persons inbox as a separate email will be sent of smaller size.

    I basically want the email that was sent with the attachment deleted so it doesn't clog there inbox up.
    Last edited by dave1983; 01-24-2017 at 10:28 AM.

  10. #10
    Forum Contributor
    Join Date
    04-17-2012
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    122

    Re: Macro to delete email as per string or cell data

    Just in case its useful for others on this subject this really helps

    http://excelmatters.com/2013/09/23/v...-late-binding/

    Ctop I know see that Late binding helps deal with issues around version of program etc.

  11. #11
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to delete email as per string or cell data

    Hi dave1983,

    It's not a question of Early vs Late Binding. My personal preference is late binding which doesn't require a library reference, and is independent of Office Version. However, if any references are made to Outlook Enumerated constants their values have to be explicitly declared.
    Enumerated Constant Reference:
    https://msdn.microsoft.com/en-us/lib...ffice.11).aspx

    For more information on Early vs Late Binding see:
    http://peltiertech.com/Excel/EarlyLateBinding.html
    http://excelmatters.com/2013/09/23/v...-late-binding/


    a. You seemed to be using the 'Inbox ' for folder 'Outlook Data Folder' instead of the 'Inbox' for the Default User Name (Account 1).
    b. In addition, you should consider using 'Option Explicit' to avoid typos from ruining your day.
    c. Try to avoid using 'On Error Resume Next'. It often masks real problems.

    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Try:
    Please Login or Register  to view this content.
    The following debugging information may help you now and in the future:
    Debugger Secrets:
    a. Press 'F8' to single step (goes into subroutines and functions).
    b. Press SHIFT 'F8' to single step OVER subroutines and functions.
    c. Press CTRL 'F8' to stop at the line where the cursor is.
    d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
    e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
    output to the IMMEDIATE WINDOW.
    f. Select View > Locals to see all variables while debugging.
    g. To automatically set a BREAKPOINT at a certain location put in the line:
    'Debug.Assert False'
    h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
    if i >= 20 and xTV20 > 99.56 then
    Debug.Assert False
    endif
    i. A variable value will be displayed by putting the cursor over the variable name.

    To manually set a breakpoint, see http://www.wiseowl.co.uk/blog/s196/breakpoints.htm
    Lewis
    Last edited by LJMetzger; 01-24-2017 at 12:12 PM.

+ 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] macro to delete certain data in a cell
    By james1432 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-16-2013, 11:11 AM
  2. [SOLVED] insert variable string in email macro
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2013, 06:47 PM
  3. Send New Email W/ Body of Received Email, Then Delete Sent Email
    By edneal2 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 07-01-2013, 12:45 AM
  4. Macro to PDF a sheet in workbook and email (outlook) to an email address in a cell
    By paul_sykes00 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-17-2012, 12:54 AM
  5. [SOLVED] Macro VBA Help: Delete a cell in a row if containsa a text string.
    By joannakf in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-11-2012, 11:22 AM
  6. Macro to add two dimensional string array as email body.
    By duran16 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2012, 01:14 PM
  7. [SOLVED] macro - delete row if cell contains string
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-16-2006, 08:45 PM
  8. macro - delete row if cell contains string
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-16-2006, 01:52 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