Outlook Search Folder Criteria - vba

Is it possible to set criteria of a Search Folder in Outlook to a large number of keywords, like this:
subject contains "abc" OR "def" OR "ghi" ...
Search for the word(s) box in Search Folder Criteria does support comma-separated list of values, but the max. length of that box is quite limited (255 chars I guess). The number of keywords I have is very large (hundreds of them). Adding them manually through Advanced tab is also a pain, so I'm looking for a more programmer's way. One of the following should work:
If Outlook stores these criteria in a flat file somewhere (like Thunderbird does), I'll edit it directly and inject my keywords into it.
If I could manipulate the criteria through Object Model (VBA), that's also a good solution.
If VSTO can do it, I have that experience as well.
Does someone know if any of the above method works?
Note: I'm using Outlook 2013 if that has something to do.

You can develop either a VBA macro or an Outlook add-in (VSTO can be used for developing an add-in). Try using the AdvancedSearch method of the Application class. See Advanced search in Outlook programmatically: C#, VB.NET for more information.

Related

Using content of a specific cell to determine in which folder an Excel spreadsheet is saved

I have an Excel template that I use to keep information about various clients. These clients can be in various stages of the process such as "submitted", "pending", etc. The status of the client will determine in which folder the information spreadsheet is saved (i.e., there's a folder for all "pending" clients, a folder for all "submitted" clients, etc.). I was wondering if anyone knew if there was a way to write a Macro that could "read" information from a 'Status' cell and, depending on what was saved in that cell, save the Excel sheet to the correct folder?
I agree with the comments: the macro recorder is the easiest way of learning the syntax of commands that you can use from the keyboard. However, I do not believe it will help here.
When the macro checks the status cell, it needs to close the client workbook (I assume it has already been saved) and then move it from its current folder to the new one. I do not believe there is any way to get the macro recorder to record the statement that moves a file from one folder to another.
Small, easily written, macros can be used to perform a wide variety of tasks. You need to have some pretty advanced requirements before Excel VBA will not be adequate. I recommend everyone learns VBA. Search the Internet for "Excel VBA Tutorial". There are many tutorials and most are free. Try a few then complete one that matches your learning style. Alternatively, visit a good library or bookshop where you will find a selection of VBA primers. I recommend visiting the library and trying a few primers before visiting the bookshop to buy the one most suited to your needs. Learning VBA will not take too long and the investment in time will quickly repay itself.
Your macro will have to be in a master workbook which accesses and updates the client workbooks. Many of the answers here show how to work with multiple workbooks. Try a few search terms and I am sure you will find something that gets you started.
Look up "FileCopy Statement" This is the simpliest way to copy a file from one folder to another. The Move method which involves use of FileSystemObjects is more complex but more flexible.
Good luck and welcome to the joys of programming.

Add VBA Project to Visio Document by Using Code

I've been asked to create a macro to update a few hundred or so Visio drawings, and keep them updated.
The update involves putting all objects of a certain type on their own layer - simple.
Now, this is easy enough to do, but when a user adds a new object some time in the future it will likely be on a default layer. So I had hoped to be able to include a VBA macro which is triggered by the Save event to re-assign objects to their layers.
The problem here is that I'd need to include this macro in every document since Visio doesn't have an application level VBA project.
Is there any way to introduce a VBA project to ALL Visio documents using code (VBA or otherwise)?? Or is there an alternative I might not have considered? Unfortunately an Add-in is not really an option due to available resources.
You have a couple options here:
Force every user to allow programmatic access to the VBA project for their documents, and use VBA automation to add code. This works nicely when you have programmatic access, but this can be difficult to assure.
If you're not using Visio 2013, you can actually save a document as VDX (xml) and replace the data for the VBA project with your own (you'd save out a document as VDX manually, and copy out the chunk of data for the VBA project). As I said, this wouldn't work with Visio 2013 since they seem to have eliminated the VDX format. You probably can get away with something similar with the VSDX XML format for 2013.
You can 'migrate' everyone's documents to a new VST file you provide. This would just involve copying and pasting all the content from a document into the new document that has your code in it. You have to be careful though to make sure all the document- and page-level data comes along, too (meaning DocumentSheet and PageSheet and any Document XML properties that may be important, and attributes like Author, Description, etc...)
Item 1 is the easiest, aside from the pain getting programmatic access to VBA Projects, unless you can have people send you documents to migrate.

Using data from Ms-Excel to fill a pre-defined template in Ms-Word through VBA

Summary: I have to fill reports in excel and then manually copy the same in doc as required by my seniors to track bugs in different applications. The excel and doc report is different for every application. So I want to save work as I fill a excel and export it in the agreed template in word.
Problem : I am trying to write a macro which will search some variables in pre-defined template (doc) and replace these variables with data from excel. The variables are nothing but some text like <-AppName->, <-AppID-> (self created). Now there is a twist as there is one sheet in excel which has issues marked as high medium and low. I want to export this list to same doc as three different tables marked as high medium and low.
Question: How to populate variables (as above) in doc using the data from excel via VBA? If at all I can populate variables how do I manage to export the data from excel to doc in three different tables since it will have multiple lines.
Thanks in advance.
I haven't gone in-depth to look at this but I don't see why it wouldn't work.
1) Set up your library references in your VBA project so you can access Word's VBA API.
2) In Excel VBA method, set up an array of your search/replacements.
3) In that same module, open the Word file(s) and replace the variables. Like I said I haven't fiddled around with the API so I can't say if you can do this easily...but also check this out.
4) Save the word documents as new files, close them.
I'm not sure what you mean "three different tables" but once you figure out how to find/replace that part should be a breeze.

vba variations across office suite

what kind of functionality variation is there across vba for excel vs vba for access vs vba for word, etc..
i know that probably 95% it's the same. but what is that 5% of differences consistent of?
Open a VBA editor and go to the object browser (F2). Click the dropdown that says <All Libraries>. Here you can see all the libraries available by default in the current application. Regardless of which application you're in, you'll always see the Office, VBA, and stdole libraries. You'll also see a library with functions specific to the current application: Word, Excel, etc.
If you look at the application-specific libraries you'll see that they contain objects and methods specific to that application - cells, worksheets, and formulas in Excel; paragraphs, styles, and mail merges in Word; etc.

Storing arbitrary meta-data in Microsoft Word document

I need to store custom meta-data in a Word document. The 'document properties' are limited to 255 bytes but I have data which is >> 10k
We are using VBA to write a word extension to interact with our application and want to have our application data stored in the word document. The idea is that that the user can share just the word document without sharing any other data files of our application.
Has anyone ideas how to store arbitrary meta-data efficently in Office 2003+ documents?
Just tried this in the VBA editor immediate window:
ActiveDocument.Variables.Add "foo", String(10000, ".")
? Len(ActiveDocument.Variables("foo"))
10000
Document variables are stored with the document. They seem to go up to 65280 Unicode characters, as I just found out (tested in Word 2003; Update: This limit is the same in Word 2007 and 2010).
If you fear to get near the 60k for your data, I'd recommend either splitting it over several variables, or compressing it before you store it. This post shows some options to do that in VBA.
It fits not exactly your requirements because it does not work with Word 2003. However, it still might be interesting to you (otherwise I recommend you to use document variables as suggested by Tomalak):
In Word 2007 (and later) you may embed arbitrary XML documents in a Word document as Custom XML.
An example is described ins this article on MSDN: How to: Add Custom XML Parts to Documents by Using VSTO Add-Ins