+ Reply to Thread
Results 1 to 12 of 12

Need VB Code to Extract email address from File name and email the file

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Need VB Code to Extract email address from File name and email the file

    Hi:

    I have lots of files every day which needs to be emailed to client.
    All these files are in C:\"To be Emailed"\
    Currently I manually email each file thru Oulook 2010 and this takes lot of time and mistakes.

    The structure of the file name which are in the above location :
    Date_ClientName_Clientemailaddress
    Example of file name : 07-27-2012_rizmomin_rizmomin@comcast.net
    07-27-2012_JohnDoe_Jd@gmail.com


    I would like to have a VB Script/Macro which will email all files and move the all the files to new location when done.

    The body of the email should just say :

    "Please find attached the file
    Thank you
    Riz Momin"

    Please let me know if you have any questions.

    Thanks

    Riz

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,527

    Re: Need VB Code to Extract email address from File name and email the file

    =MID(A1,(FIND("_",A1,FIND("_",A1)+1)+1),LEN(A1)-(FIND("_",A1,FIND("_",A1)+1)+1)+1)

    This will extract the email name, assuming the format is consistent.

    There are lots of examples of sending emails in Excel ... see Ron de Bruin's web site.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Need VB Code to Extract email address from File name and email the file

    Hi TMS:

    Not all files which needs to be emailed are excel.
    Some files are excel and some pdf.
    So I would not be aboe to use the above formula.
    Please help...

    Thanks a lot in advance.

    Riz

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,527

    Re: Need VB Code to Extract email address from File name and email the file

    You've posted in an Excel forum ... I therefore assumed your file name/email address was in a cell in an Excel worksheet. I've given you a formula to extract the email address. You could use a similar formula to extract the file name. Then you could have a loop to process each of the pairs.

    If that's not what you want to do, please provide some clarification.

    Regards, TMS

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Need VB Code to Extract email address from File name and email the file

    Hi TMS:

    Thank you so much for your response.
    But as i said i have pdf files also to be emailed.
    Please refer to attached pic that shows that these are the files emailed and as mentioned each file has emailed address which needs to be extracted.
    Please see if you can help.

    Riz
    Attached Images Attached Images

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Need VB Code to Extract email address from File name and email the file

    Hi:

    Please help me get VB Script for above task (.vbs)

    Thanks a lot

    Riz

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,527

    Re: Need VB Code to Extract email address from File name and email the file

    I will ask around for you but I think you are looking in the wrong place. You need a VB or VBS forum, not an Excel VBA forum.

    Regards, TMS

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Need VB Code to Extract email address from File name and email the file

    Hi Riz,

    As TMShucks stated, this is an excel forum, and therefore any solution would 99.99% be Excel-based. Now what you are asking can theoretically be done using Excel visual basic for application (VBA)... but is really a project not a question. Therefore you will need to find someone to really want to undertake a project for fun. Right now, I'm not taking on any new projects but wanted to give you the basic truth so that you can truly reflect on this and tell us if there is anyway we can help answer a specific question.

    Good luck.

    abousetta

    P.S. There is even a canned response for situations like this:

    This is a pretty big request in one chunk. I'm sure you'll get better response if you break down your question into several parts, so that they can be tackled one after the other.

    Also, we're happy to help you with your effort, but nobody here will be keen on developing a solution from scratch. This forum is about helping people learn how to use Excel, not a free development service.

    Have you started any work on this project yet?
    How far did you get?
    Where are you stuck?

    We can help you develop your own code, but if you want someone to code this for you all the way, you should try and find a commercial developer.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Need VB Code to Extract email address from File name and email the file

    I don't think this is a particularly big request and I think VBA code is similar enough to vbs to offer a solution, FWIW you could use this from Excel also

    This will work for your examples, however the _ as a space is a poor choice since this is a legal character in email addresses. How would you distinguish between the end of someone's name and the email address if it has a _ in ?

    Please Login or Register  to view this content.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,527

    Re: Need VB Code to Extract email address from File name and email the file

    @Kyle: so that's the VBS? I guess I probably could do that with a few worked examples.

    Thanks, TMS

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Need VB Code to Extract email address from File name and email the file

    Yup, thanks for the feedback it's very similar to VBA just not strongly typed so all late binding, so you obviously can't use any office function in it, although you can create instances of office and use them just like you would in VBA
    Last edited by Kyle123; 07-30-2012 at 06:08 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Need VB Code to Extract email address from File name and email the file

    Hi Kyle23:

    You are great and geneous.
    This works very good.
    The only thing left is to see if the files get moved to another folder once email task is completed.
    Also is it possible that this can be emailed in the background instead of actually sending each file thru Outlook.

    Thanks a bunch

    Riz

+ 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