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

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.

Related

Can there be more than one VBA project open at the same time?

I have a VBA project provided by my company. It is password protected and I cannot add new modules to the project nor can I have a second one open at the same time.
Could I either remove the password from that VBA project, have a second project open at the same time, or still run my own custom macros at the same time?
I basically want to use the company macros as well as my own.
You can't have multiple VBA projects opened at the same time. But you can have multiple modules opened, imported and exported. So, following that way with modules you can have both solutions working in Outlook.
As I already wrote, Outlook support only one VBA project at a time. On the other hand, one can select, which of all possible VBA projects should be used at start. VBA project is saved in separated OTM file, located at %appdata%\Microsoft\Outlook.
To start other VBA project than default, one has to enable this option, a corresponding registry value is listed below:
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Security\EnableAltVba
It has to be set to 1) and then after Outlook can be started with command line switch
Outlook.exe /altvba \\MyServer\MyShare\otmfilename.otm

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.

How to password-protect a VbaProjectPart using OpenXml SDK

I have a scenario where users download their Word document from our local server and when they save that document, instead of saving it locally, the document is sent back to the server using a macro (which is "injected" by the server every time a user downloads a document that doesn't contains the latest version of the macro).
Now that we are going to send this solution to our final tests prior deploying it, we needed to protect that macro, I know I can password protect a macro using Microsoft Office by simply right clicking in the macro project inside the document and selecting "block from viewing" and inserting a password.
However, since the macro must be handled by the server, I need to find a way to protect that macro when I generate it, currently the macro is generated using OpenXml SDK using a VbaProjectPart. I couldn't find anything on the web.
Instead of trying to sign and protect the macro programmatically using Open Xml SDK I decided to download the document, sign it and protect it using word then I used "Open Xml SDK Productivity Tools" to "reverse engineer" the DOCM created and then I copied the binary "VbaProjectPart" created by the tool.
It's not the best way to do it since I need to have a separate documentation for this process and need to do the whole process when the macro changes, however, since the code isn't expected to change anymore I decided to go that way.
Hope this helps anyone who wants to know how to include password protected macros inside an Open Xml document.

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).

SSRS 2008: How to generate multiple reports immediately?

Im building a site which brings up SSRS reports by opening new windows with the report url and report parameters. I can currenlty open a window for each report they want to run.
However, they also want the option to save the reports to a file share or Sharepoint of their choice, instead of having a bunch of browser window pop-ups for each report.
I understand I can use SSRS web services to setup a schedule (to run in a couple minutes from the time of request) which can save those files to a file share (or Sharepoint) but that seems like a hack to get a one time generating of reports onto a file share or sharepoint.
Is there any other way to instantly generate a bunch of reports, one time, immediately, without having to set them up on a scheduler that is set to run a couple minutes from the time they set it up?
"Note, they DO NOT want one report that has all the reports in it, these are seperate reports that are already built, and they want one file/window per report."
Not sure what you want when you say you want them all at once but one file window/per report? What presentation layer is showing this? You can make three seperate web calls at the same time to the webservice instead of the hosting site:
h ttp://(servername)/(ReporstServer)/PathtoReport1
h ttp://(servername)/(ReporstServer)/PathtoReport2
h ttp://(servername)/(ReporstServer)/PathtoReport3
instead of
h ttp://(servername)/(Reports)
If you just mean 'separate pages' on an Excel workbook you can do that with one report nesting other sub reports. You can build a master report that has rectangle objects that define pages as their properties and place a sub report in each of these rectangles.
Or you could make an html page that references the calls three seperate times in a 'form' object of the HTML doing a 'post' command.
< Form id="SSRSRender" action="http://(servername)/(reportServer)/(report) method="post" target="self">
"However, they also want the option to save the reports to a file share or Sharepoint of their choice, instead of having a bunch of browser window pop-ups for each report.
I understand I can use SSRS web services to setup a schedule (to run in a couple minutes from the time of request) which can save those files to a file share (or Sharepoint) but that seems like a hack to get a one time generating of reports onto a file share or sharepoint."
That's not a hack, that is the preferred method of saving a file is using the built in web service scheduler. Once a report is hosted (on a server hosting the SSRS) it can have configs set for SMTP send outs, file saves, and snapshots made.
If that is not enough you can create your own proxy classes if you want in C# or VB.NET and try to build your own front end talking to SSRS through SOAP requests to the Web Service.