简体   繁体   中英

Pasting multiple ranges from multiple sheets into a single email from excel

I come to you today seeking advice. I am using excel 2010 at work an I am using VBA to automate it and my Outlook account. I have a Workbook with multiple sheets to track the weights of various assets stored in multiple buildings. I have it set up now to whenever a user pushes a command button it will open outlook, copy a range, paste it as HTML in to the body, and fill out the To/CC/BCC/Subject lines, but for the life of me I cannot figure out how to get it paste multiple ranges on separate sheets into the SAME email when I need to update multiple buildings. I can post the code on Monday as I do not have access to it now. Essentially all I need to know is what command (like OLinspector, getobject, etc etc) will make the program recognize if an Outlook email instance is already running and paste x amount of other data that the user desires. This does not need to happen simultaneously, as the user must update multiple sheets and push a button to save the data to a database.

You don't have to "detect" anything. That will make things more complicated for you. The best option you can take is use the ever-useful and very famous methods of Ron de Bruin for Excel-Outlook integration, particularly pasting ranges into an e-mail's body .

Granted, you have your own code but if it's not based or similar to the one posted above, you have one disadvantage: pasting into the e-mail's body is not a nice way of doing it. Setting .HTMLBody to a range converted to HTML is much better.

One way I'll do the your process above is simple: I'll write a separate subroutine that creates a dummy sheet, pastes all the ranges/tables/cells/what-have-you there, and feed it to the sending subroutine above. That way, they are all consolidated in one area the way I want before they are transformed into HTML and used as the e-mail's body.

Let us know if this helps you in any way. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM