VBA to Archive Emails in Outlook - vba

I'm using Microsoft Outlook for Office 365 (desktop app, not the web version). My emails periodically archive to the Online Archive folder, which I like because I sometimes need to access archived stuff in the last few years from webmail. But beyond a few years back, I manually move emails from the Online Archive folders into folders in .pst data files that are stored on my hard drive.
Unfortunately, the process of moving the files from the Online Archive to the .pst files is really slow/delicate. If I select more than a couple weeks of emails to move at one time, that move process can take a really long time (hours). And, maybe more of a problem, if I try to move more than a couple weeks of messages, Outlook will often crash (and I'm never confident that some emails weren't lost in the move). So what I end up doing is manually moving just a few days of emails at a time, which eats up a lot of time and requires my attention.
I'd like to write a VBA subroutine where I could specify the source folder (inbox or sent folder from my Online Archive), target folder (folder in an open .pst file), and a year, and then the VBA would move all of the messages from the specified year from the source to target, but moving only a day of messages at a time (or maybe a few days at a time).
I know VBA for Access and Excel, but no idea really where to start with Outlook. Much web searching has not really surfaced any useful info.

Related

Mozilla Thunderbird: recovering emails from global-messages-db.sqlite

How can I recover lost emails from Thunderbird's global-messages-db.sqlite?
My PC kernel panicked in the middle of migrating some emails from Imap to local storage. As a result, that migration did not complete writing to disk.
Due to the failed migration, many emails exist in global-messages-db.sqlite but do not exist in corresponding mbox files (eg not in Mail/username#hostname.tld). I verified that the emails exist in global-messages-db.sqlite via sqlitebrowser. In fact, I've successfully manually extracted the content of some critical messages.
Upon startup, Thunderbird is culling from global-messages-db.sqlite emails it does not find in mbox files. If I replace the active global-messages-db.sqlite with a version containing my lost emails, Thunderbird ignores and eventually removes those lost emails.
This would be a trivial dilemma if I still had access to the Imap account. Unfortunately, I do not.
Scripting a converter is trivial
I would quickly code a gloda->mbox converter, that's probably your fastest path to success. You've already discovered the structure of the gloda database. Now, it's just a matter of writing a little JavaScript in node.js that opens an sqlite database, iterates over the folders, then the messages in each folder, and writes an mbox file for each folder. The mbox file format is trivial (just pay attention for "From"). Once you have that, you can open these mbox files in Thunderbird by just overwriting an existing empty Local Folder.
P.S. Just as a reminder: Make backups. Esp. before such migration operations, but also regularly.

Best way for Excel workbooks to share VBA functions

I seek advice on how to manage userdefined VBA-functions that are used in several workbooks:
Background:
Over time i have created several Excel workbooks (wbs), each with a slightly different purpose, that are ultimately based on a library of my userdefined functions and class modules (From now on: library). The "master"-versions of the wbs are revision-controlled. The wbs are used by several people.
However, I do not use an addin for the library, and hence the modules and class modules are actually locally present in each wb's specific VBA project. This makes it a nightmare when doing either expansions or corrections, as I have to revisit and implement said alterations in each wb.
Furthermore, in each wb there are unique functions, understood such that those are not intended to be shared. Those functions, however, might utilize the library-functions.
Main-Question: How should one manage vba functions across several workbooks shared by several users?
My considerations/Sub questions:
Should I convert the library to a true addin and discard the local copies in each wb?
How do I tell the users that the add-in is required upon getting a copy of the maser-version?
How does one cope with legacy/local versions/branches that are spread among the users? Both current legacy copys and future legacy copies that might be used for reccuring tasks?
Where should such an addin-in be stored (in a shared folder or something)?
Would it be considered "bad practice" to force load the add-in using the workbook_opensub?
Any advice or guidance in best practice is appreciated.
Edit: I have tried to highlight the main question, please consider the sub questions as my own thoughts on the subject.
Until recently, I had several add-ins that lived on a shared drive. I had the users install the add-in using File - Options - Addins and wrote up the instructions to do it. The copy on the shared drive was read-only. For changes, I would code and test on the dev copy on my machine, then deploy it to the shared drive. The next time the user started Excel, the changes would be there.
Then we wanted more people to have the addins and not all of them had access to this shared drive. Also, people complained when they were off the network that it still tried to connect to the addins. So we went a different route.
We used a program called PDQ Deploy to put the addins in everyone's addins directory, so they had a local copy. We also deployed a script that copied the files from a company-wide shared drive to their addins directory. If they weren't connected to the nextwork, the script would fail silently. Finally, we used group policy to 1) create the registry entries to install the addins and 2) create a scheduled task that kicked off the script every night. Updating every day is overkill, but the files are only a few kbs, so we went with it.
Now I can deploy new versions to the company-wide shared drive and everyone will have the changes the next day (or the day after they're back on the network).
I put my vba stuff on the "personal" workbook (Windows menu : Unhide...) and whatever workbook I am using I can use them from there.
You do have to make sure about knowing which one is acrtive though...

Excel vba macro to download a file automatically when it's added to a Sharepoint site

I am running an excel macro, it downloads some files from SharePoint. It's working fine but my problem is, Everytime i need to check if the file exists there or no then i download it.
Is there a possibility to add a condition when the file is added on SharePoint then the macro will run automatically. Because the reports are uploaded in different times by other users for example one day at 9 am, another day 11 am, another day at 1pm... and now i am checking everyday many times on the sharepoint site if the report was added or no before i run my macro.
I want to avoid this and link somehow the sharepoint site to my macro.
For example for the reports i receive on Outlook i created a macro when i receive an email with attachment containing a specific name it will download automatically. I want something similar on Sharepoint without checking everytime on Sharepoint if the other users uploaded their reports or not.
Any suggestion please ?
Assuming that you are using SharePoint 2013 OnPremise you can write an ItemAdded event receiver which will execute your macro (you can do this only if you are allowed to deploy code to SharePoint).
You could also write a Service / Job that will run every 5-10 minutes and check which files have been added in the last 5-10 minutes (this frequency will depend on what is the urgency for executing the macro), download the file and then execute the macro on those.
Irrespective of the environment this code could run directly from your local machine if you have no good place to host it.

Outlook VBA module changes not saved after restart

Good day,
I have a VBA script running as a rule for a few months now, which basically saves some attachments from a specific sender into some folders. Recently, the module had to be edited to add a few lines for a new Folder. The new script worked as expected the day it was implemented. The problem is, the next day, after shutdown, all the changes made were reverted to the previous version. So, it seems I am stuck with that first script made.
How can I edit the script and actually have the changes saved?
PS. We are using MS Server 2012 and Outlook 2013
We saw this happen with roaming profiles.
We noticed that the modify date of the OTM file is not changing in C:\Users\"usename"\AppData\Roaming\Microsoft\Outlook
Therefore, when user logs off and profile synchronizes back to the profile host server, this file does not appear to have changed, and does not get synchronized. When user logs in next day and downloads fresh copy of profile, they keep getting old OTM file...
Our solution was to write code to manually change the modify date of the OTM file in the VB script.
I bielive the issue comes from the roaming profile. See Where does Outlook store the VBA code files? for more information.
There is a chance you closed Outlook without saving the VbaProject.OTM. You may find the following commands on the main menu or on the command bar:
You may find the Getting Started with VBA in Outlook 2010 article helpful.

VbaProject.OTM deployment

I came by this page and was thinking about the best method to distribute my VbaProject.OTM file (located into %appdata%\Microsoft\Outlook\) to a bunch of ~30 users at my office. Is it better to simply copy/paste the OTM file onto the network and then copy/paste it back to all users' computers (manually or with a .bat) OR would it be better to use the method described in the link above to generate a OPS file and import it back with Proflwiz.exe? What's the difference?
We are all on Microsoft Office Outlook 2003 actually, we might upgrade to 2007 one day but still years from now.
Finally came up with some elements to deploy a Outlook VBA Project. There are a lot of ways to do this, but the easiest way to do so without installing anything and keeping the same methodology would be to run a OTM file directly from a server. I found out that the process outlook.exe has a parameter altvba that allows to specify another path to run the OTM file from. Here is en example:
outlook.exe /altvba "\\myServer\myFolder\myFile.otm"
This allows me to update only one file to get all computers updated. Obviously, if the file is big and the server's ping is on the high side, it may delay the launch of Outlook. The other problem with this method is that everybody will have to shut down Office if you want to update the OTM file on the server (and if you do work in an office where everyone uses Outlook, you do know that it is impossible to get everyone to shut it down at the same time, except if you code a macro to do so eventually). To prevent both those problems, I could setup a batch file to copy the server OTM file clientside everytime there is a new version (just have to check the NTFS last-modify attribute). This way, Outlook will boot with a local file, the batch file take 2-3 seconds to copy the file if needed (or will launch Outlook instantaneously) and there will be no problem updating the OTM file on the server. Users will have to start Outlook with the batch file (or with the slightly different outlook.exe path with the altvba parameter, so either way they need a different shortcut/file to start off the first time). One other advantage of the altvba is that it's still easy for the user to run Outlook without it (to see if the VBA is problematic or not in case Outlook is sluggish) and the file will remain unchanged after a Outlook reinitialization.
Others solutions include a COM complement that can be developed in a lot on languages including VB6 (no conversion needed from VBA). There is also a bunch of tools included into Microsoft Office XP Developer that could help getting the job done (not free however, especially if you need the most up-to-date version).