+ Reply to Thread
Results 1 to 3 of 3

Attach excel file at an email created via VBA

  1. #1
    Registered User
    Join Date
    08-08-2020
    Location
    Frankfurt
    MS-Off Ver
    2013
    Posts
    17

    Attach excel file at an email created via VBA

    Dear Everyone
    I would like to kindly ask for your help. I am new to VBA coding and thus I would like to kindly ask for your help regarding an issue that I am facing. Thanks in advance!
    I have been asked to create a VBA code that automates a message and sends it as an email in outlook. In addition, I also need to attach an excel file with it. My struggle is that the excel file is not static and changes each month. Imagine Revenues_July, Revenues_August etc. The vba button will be inserted in a file named Market Activity however each time that I enable it I want it to attach the Revenues file from the previous month. So in September I want to have attached the Revenues_August file, in October the Revenues_September file etc. How would it be possible to make a code that is not dependent on one specific name? I know that there is a way to do it by attaching the active workbook but that's not what I want since the button will be on a different folder. Can someone with relative experience help me please and explain me what to do in a simplified way?

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Attach excel file at an email created via VBA

    you need to research the VBA object model. just like any language, there are endless amount of resources inside of it. technically, the way you attach a file of ANY type to an outlook message is with a method called attachments.add and it is associated with the mail object in Outlook's object model, also the VBA language. here is microsoft's official documentation on the entire language of VBA, and every single resource you need can be searched for on these pages: https://docs.microsoft.com/en-us/off.../api/overview/

    as you can see, every office program has its section. also, if you want a really interesting architectural layout of the entire VBA object model, including every single thing you can use within it, take a look at the attachment I've given you. I did this a long time ago, and the purpose was to show the relational and pattern-based nature of a very old language (this case, VBA). However, every single programing language in the world can be shown in this exact same way. Funny thing is, most "professionals" are so smart, they don't realize this. Rather, they are stuck in the mindset of thinking about things in terms of ""frameworks"". and that's perfectly fine. so, with all that said, good luck with this project and you are certainly welcome to post specific questions. Many people here can answer them.

    (file is on the google cloud. sorry. it is too large to upload to this forum). it's 4 megabytes.

    VBA Complete OOP Architecture (v. 2007 -2016)

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    6,986

    Re: Attach excel file at an email created via VBA

    .
    You can simplify the entire process by placing last month's file in a folder by itself. Always use the same folder for the previous month's file (workbook). And
    it should be the only file in that folder.

    The remaining part of the project is a matter of coding what you want. Here is a link to creating VBA code that creates an Outlook Email via VBA :

    https://www.rondebruin.nl/win/s1/outlook/mail.htm


    The are tons of example project on this Forum and others that will provide complete examples of the finished project you are seeking.
    Search for Email Via VBA Attachment. You can also Google same.

    Once you get something started, post again for any assistance you require.

    Best wishes.

+ 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] Attach files to email created in Mozilla Thunderbird using VBA
    By rrpinto in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-06-2020, 04:10 AM
  2. Using .attachments.add to attach an excel file to an outlook email
    By mirandajean in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-19-2017, 11:48 AM
  3. Attach files created by macro to an email
    By JesseSingh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-04-2016, 12:12 AM
  4. [SOLVED] VBA Using Excel to Attach file to Email
    By knighty2002uk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2014, 10:27 AM
  5. [SOLVED] Create an email in Excel and attach the file as a PDF
    By MissDB in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-21-2014, 09:50 AM
  6. [SOLVED] Attach a file and email it using Excel.
    By Paul Morgan in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2012, 09:32 AM
  7. [SOLVED] How Do I attach a atachment to a VBA created email?
    By Dan Gardner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2005, 04:06 AM

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