Pasting multiple ranges from multiple sheets into a single email from excel - 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. :)

Related

How do I extract data from an excel document attached to an email (Outlook 2010)?

I've seen loads of questions and answers to similar items but not quite the same.
I receive emails each day that have excel workbooks attached. I only need to use certain data contained within those workbooks so am after a way to do so without needing to open the email or the excel attachment.
NB - I have a number of stored emails so would like a way to perform this activity against those emails in one hit. IE not have to manually open each mail and/or workbook to see the values of interest.
I'm sure its possible, as it must have troubled people in the past, but I'm not sure how!
Please help!

Is there a way to make a logbook in excel of files being created?

I want to make a dynamic excel sheet that updates whenever a file is being created into a folder, think of letters. So the sheet needs to extract the name of the letter, the date&time when it is made, the author and so on, into a table in excel. Does anyone knows how to get that filedata?
I already know how to put data in a certain cell using VBA but the thing i get stuck in is how to get that data from a certain folder.
As Ron said, there is no event in VBA to handle that. However, if you want to stick to VBA only, you have basically two options:
You can update your cell whenever the workbook is opened using the Workbook.Open event (https://learn.microsoft.com/en-us/office/vba/api/excel.workbook.open). This is not really dynamic but might be sufficient (depending on your needs).
Other option would be to call a function periodically to check if the folder content has changed (https://learn.microsoft.com/en-us/office/vba/api/excel.application.ontime)... Not very performant, but would work for sure.
For the file data just follow Ron's suggestion.
Hope that helps, MJ.

Weekly report automatisation

I have to code an automated mail. This is a weekly report, containing texts, outlook tables, and up-to-dates excel charts. edit: before sending it, I need to check the mail.
I don't know what is the better way to code that and I want your point of view.
My first option is to create a special workbook with a new macro, and do everything with this new macro. I don't see any problem in managing multiple others workbooks and charts. But I am not sure if I can easyly works with the mail. Would it be possible to write/create table in outlook from excel ?
My second option is to work with outlook. I think I can write some code somewhere to launch excel macros and updates my tables. But i don't know much about this.
What would be the better approach ?
Edit: Let's say that I am just a little intern (lucky enough to make others thing than coffee), and the report is for my manager's manager's manager. No flexibility.
I would just email them the workbook with the report information in it. If they are employees of your company and they recognize your email(or the company's email) there shouldn't be a security issue with just sending them the workbook as an attachment with all th reports in it. You should be able to do that from Excel: http://msdn.microsoft.com/en-us/library/office/ff458119(v=office.11).aspx
You can update the excel file and then concatenate your data together to form the email body as well if you want - as well as obviously email the workbook itself or another updated workbook if you want.
Would be a big project if you are a beginner with VBA but is certainly doable.
If you're working with Outlook, you may also have access to 'SkyDrive' which will allow you to upload documents and files to shareable folder(s) and then send out alert emails to those sharing the folder. Probably a lot easier than writing some code that will most certainly have a never-ending maintenance burden.

Excel master sheet

I have an Excel sheet which is used for bug-tracking. Each client has their own .xlsx and each application for that client has its own sheet within the .xlsx. So multiple Excel files with multiple sheets, all in the same format.
All sheets have the same headings and some columns have data validation and conditional formatting. Occasionally, however, the layout/headings or values allowed in data-validated cells, etc. must change and I have to go through each sheet and manually make the changes.
Is it possible to have a master sheet from which other sheets will inherit headings and heading styles with all cells under particular headings having data validation and conditional formatting?
(Before this is suggested, I used to simply put everything in one sheet and use filters to show a particular client/application, but this became impractical when sharing and versioning the sheets with multiple people)
The term you are looking for is a template. You create the template and give that to your 'clients' to track bugs. If you make an update to the template and give it to the client, they can just copy/paste data into the new form.
In my opinion, you're going about this the wrong way. Excel is a spreadsheet programme, while it CAN be used as a 'list' of sorts, it is a poor choice for bug tracking. If you're stuck on Office applications, use an Access database or something that can actually give you a 'front end display' separate from the 'back end data'. There are many free bug tracking software programmes on the internet. Set one of them up and just have your clients log a bug there.
Using a template and then getting the clients to copy+paste the old data is one way, but its not exactly the safest method.
If you did want to distribute a new template to your users it would be a good idea to add some import functionality. So VBA handles copying the old data across.
If you (personally) could do the changes to the template manually, then you might also be able to create a workbook+macros to "patch" the source (or a copy of the source) data in-place.
With either approach you'd probably need to add something to the source workbook to keep track of what version they have and make sure they they import from and to the correct version to prevent unhappiness in the future.
Could you show an example of a change? before and after etc

Saving individual sheet in Excel VBA

Currently we have a Excel VBA application, which consists of 25-30 Excel sheet (and all of those sheets all hidden and we do background processing on them and display it to VBA forms UI), and we have developed a UI using VB forms. But problem we are facing is whenever we click on Save button using this code:
ThisWorkbook.Save
But this saves entire workbook not an individual sheet, so even if we make changes in single sheet it saves entire workbook and this save processing makes very slow (since it needs to save all excel sheet containing lot of data unnecessary, even if there is no changes).
My question is is there any way we can save "only one sheet in a particular excel sheet" not an entire excel file?
Note: I am a Java developer and I worked on VBA before, But it was years back, and I have forgotten bit. Any guidance would be appreciated. Or any pointers on how to handle this situation would be appreciated. Please let me know if you need any more information, I can edit this question.
What I have tried already? I did a lot of research from yesterday, I searched in previous questions on SO, but didn't get any useful information. As per my research it says we cannot do this. Am I on right path?
The short answer is no. You cannot save a single worksheet at a time.
You may want to try to reduce the amount of data in the workbook. Try storing data in several workbooks and when it is needed, open that specific workbook, make the needed changes, and then close it.
If it is necessary to have access to all data at once then consider using access or some other database.
It is also possible that the sheets have "blank data". Cells that don't contain anything in them but excel thinks they do so when saving it tries to save way more than needed.
Assuming that it is the active worksheet that you want to save then you could do something like this:
ActiveSheet.Copy
ActiveWorkbook.Close True, "path"
This copies the active worksheet which creates a new workbook which will become the active workbook. Then just call the close method on that and give it a file name.
I think you should consider splitting your application into multiple workbooks:
The workbook that contains all the logic, user forms and programming code. This workbook handles all other workbooks as well as the displaying of it. Potentially, this could be even an "Application Specific Addin", that stays dormant but activates as soon as any of it's subsequent workbooks gets opened. For this architecture approach check out the section on "Application Specific Addins" in this link.
This workobook/add-in can also hide the other workbooks, so that the user will not notice it's multiple workbooks.
One or multiple data workbooks: Depending how interlinked the data is, you can separate this, e.g. in a "Sales data" workbook which contains the large database, as "Base data" workbook, that contains all the smaller data (e.g. products or stores tables).
This way, you can reduce the saving to the "relevant" sheets. However, of course this requires quite a bit of reprogramming - but it's worth the effort, as for instance it also allows to provide updates/bug fixes without having the transfer the data between versions, as you only need to distribute the the file with programming logic. :-)

Resources