Using the Addressbook in Outlook VBA - vba

Someone at work asked me if I could implement an easy system for him to send out Outlook template-mails based on a few parameters he could enter.
An example would be a message like this:
"Hello,
Please be informed that system **Parameter1** is current down.
Regards,"
I was thinking about making a Form in Outlook VBA that would dynamically look for the amount of times a string styled like a parameter (e.g. ##parameters##) was found in a certain template and subsequently create a editbox in the form for each found parameter.
The problem is that I obviously would like to add an box for the recipients. I would need to find a way to make the call the Outlook Addressbook and make it behave like one. This was less intuitive than I had hoped. So far I have only managed to do the following:
Dim snd As Outlook.SelectNamesDialog
Dim displayLL As Boolean
Set snd = Application.Session.GetSelectNamesDialog()
snd.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo
snd.AllowMultipleSelection = True
displayLL = snd.display()
As you can see, this only pops up the addressbook and allows me to select an few addresses. But I'm stumped on how I can actually make some fields that will actually act like the "To:" and "CC:" fields in a regular Outlook mail.

Not sure how relevant this is, considering I eventually took quite a different route, but I thought I'd still add this since no-one answered.
I simply created a form that would list all templates by searching through the templates folder in the %AppData%. I would then loop through the entire mail looking for parameter-styled strings and ask for the desired value each time I would encounter such a string (through a simply inputbox). Instead of adding a custom "recipients" box, I simply opened a new mail with the parameters filled out correctly.
The user could then simply add recipients to the mail like he usually would, and he was fine with this. That way, he was also able to double-check if the mail indeed looked exactly like he wanted to.
Nothing fancy or something that a 7-year old wouldn't be able to do, but it works.

Related

How can I show custom MailItem properties in the email header in Outlook 2007?

I work in a manufacturing environment. I am setting up some custom fields in my Outlook inbox that will allow me to quickly categorize emails by what material code(s) and lot number(s) the email is about. In my inbox, I have two new columns, "Material" and "Lot No". I wrote a macro that allows me to pull up a UserForm to quickly edit these values through the UserProperty prop on each email.
Image of columns in Inbox to demo what I mean.
I know that I can open each email individually, go to "Design This Form" and manually add the fields into the header, but this is obviously not practical (I'm doing this whole exercise to improve my efficiency, after all). Is there a way to programmatically do this?
Image of manually-added fields in email header.
I am searching all over and striking out. I'm not even able to find a good reference for how to manipulate the form elements of a received email (or at least a reference that I understand).
Thanks.
Use MailItem.UseProperties.Add / MailItem.Save to add/modify user properties.

Prevent Outlook Adding unwanted Signatures repeatedly in VBA

I want to prevent Outlook from Appending a Signature to any newly opened Outlook MailItem. When using Outlook.CreateItemFromTemplate(TemplateName) a default signature is automatically appended to the new MailItem. When working with multiple accounts attached to the Outlook Client that Signature is often unwanted, or is simply the wrong one. To make things worse, many Outlook Methods append further duplicate copies of the unwanted signature. It is possible to wind up with a whole slew of them attached.
When opening a Template, the Signature appended is the Default for the Account that was active when TemplateName was saved. It is not the Default for the currently active Account. One idea is to temporarily switch off the signature for the relevant Account and add the required Signature directly as this would be a fairly simple fix for the problem. Is there a way to switch off the signature for a specific account? I can't find one.
The signature for the Default account can be Switched off by setting
appWd.EmailOptions.EmailSignature.NewMessageSignature = vbNullString and it can also be restored later but this does not help. An idea for a possible workaround was to programattically change the default account, switch off the default account's signature, open the required TemplateName and then restore everything back to the original state. However, it doesn't work because:
a) I can't find a way to switch the Default Account programattically. It seems that this is only possible by clicking in the User Interface.
b) And it would make no difference, anyway, because the Signature for the
Account that saved TemplateName would be used despite the change.
Underlying this requirement is the fact that I need to merge parts of existing MailItems in Outlook using VBA. The objective is to merge parts of multiple items into a new MailItem for onward distribution to a mail list. The merging all works effectively using MailItem.GetInspector.WordEditor and I have sorted out the issues related to attachments and embedded pictures but the multiple Signatures, which would seem to be such a simple matter in comparison, are causing a problem. Is there way to switch them off? Getting rid of them in the WordEditor or in the HTML would be very difficult as Signatures have arbitrary structures.
Not the most elegant solution, but something like this should work.
Basically, store the HTML of the email prior to displaying, then compare it after it's shown and update the HTML if it's different.
Public Sub OutlookTest()
Dim Outlook As Object
Dim MyTemplateItem As Object
Dim OriginalBody As String
Set Outlook = CreateObject("Outlook.application")
Set MyTemplateItem = Outlook.CreateItemFromTemplate("C:\SomePath\Example.oft")
OriginalBody = MyTemplateItem.HTMLBody
MyTemplateItem.Display
If MyTemplateItem.HTMLBody <> OriginalBody Then MyTemplateItem.HTMLBody = OriginalBody
End Sub

Automatically take specific data out of specific emails and put it into an excel form

I'm completely new to VBA.
Is it possible to write some code that would search for emails from a specific sender and search inside that email for a specific line in a table, which it would then put into an already existing excel form?
Any advice on where to get started learning this or if it's even possible would be greatly appreciated.
it is possible to make that. You have three types to search something like that.
You have the View, AdvancedSearch and the Explorer.Search.
The View is only for one folder.
The Filter for the View is called Distributed Authoring Search and Location (DASL). Here is a good link for that filter type: https://msdn.microsoft.com/en-us/library/ms874577(v=exchg.65).aspx
The AdvancedSearch is like the View, but you can search over all folders and all nameboxes. BUT there is problem! When you use AdvancedSearch you have to create an folder and in this folder are your results. The filter of the folder is unchangebel, so after creading you cant change anything. The folder will update Automaticly if there are new Mail or something else. The AdvancedSearch uses the same filter as View.
The last one is the Explorer.Search. With that search you can search like the AdvancedSearch, but you have not to create an folder. This one uses the Advanced Query Syntax (AQS). Here is a good link for that filter type: https://msdn.microsoft.com/en-us/library/cc513841(v=office.12).aspx Each of the searches can filter for all typs of objects. So you can Search for things in Mails.
Text in mails is Called in..
- DASL textdescription.
- AQS contents.
I hope I could help you by starting.

Using querySaveDocument to additional information

We are trying to save some additional information with a document using the QuerySaveDocument event. However it seems that it is not being triggered at all.
<xp:executeScript script="#{javascript:setField(document1, 'cCustAddr1_fi', 'test');}">
</xp:executeScript>
This is our basic script. All the setField() method does is use replaceItemValue to try and set the field. However it seems that QuerySaveDocument is not even being triggered since we can write pretty much anything and the document will still save without problem, even if it would be impossible to execute.
We have also tried using a simple document1.getDocument().replaceItemValue() script, but again I dont think it even attempts to execute. Our documents save perfectly fine too,
Do you see any reason for this, are we doing our saving wrong, or should we be attaching data onto the document in another way?
Thanks.
Your other question on Unplugged (Using other dialog controls in iOS) suggests that you are using the Unplugged Mobile Controls project.
If that is correct then my comment above applies - the querySaveDocument event won't get fired . You can look at the code in UnpSaveDocument.xsp and possibly add your own SSJS code to that.
Alternatively, if you want an additional item created on your back-end Notes document then you should just be able to add a hidden field to the UnpFormEditor that is bound to the document1 data source and using the relevant item name you want.

VBA Macro changing macro

Is it possible to create a macro in MS Office (in this case Word) that will change other macro code? I was trying to find information but no results.
I have a doc which works as a template. Content of template is changed and then saved to another file. However it is important to have current date in it. It cannot be self-updated. Those docs go to folder of people and it is important to know when they get the document, so it must be simply data (or something that does not update).
I was thinking about an on-start event macro that would input current date and on exit it would ask "Do you want self-update functionality" Yes / No
If Yes, delete that event. However I have no idea if it is possible. If it is I still don't know how to search for it.
No this is not possible. In VBA, unlike some lower level languages when you define an event you can not disable it, even using other VBA code.
In C# or VB.NET, Java or C++ you can disable an event by un-wiring it from the handler, but this is not possible in VBA.
Maybe if you be more clear on what you need I can give you a better answer.