We have created a macro to run in MS access (Office 365) on windows server 2012 so that it runs script that creates and sends emails via MS outlook. We can run the macro from inside MS Access but we cannot get windows task scheduler to automatically schedule this process. What we are doing is creating invoices for our customers automatically using MS Access. The macro works perfectly if we execute it within the open file. It creates all the emails with an invoice attached as a PDF which is then sent via outlook to our customers. This is all done with one click of the macro. But we cannot get this process to schedule via windows task scheduler. Can anyone help?
I am answering my own question as the comments don't allow enough info to be posted.
We have finally managed to do this using the suggestion in one of the above comments to use Outlook reminders rather than task scheduler.
This solution involves setting up a task and scheduled reminder in OUTLOOK.
The recurrent schedule for the reminder in Outlook acts as a replacement for Task Scheduler.
We categorised the reminder to aid the exact identification. (For task add new category and give it a name)
The VBA script in Outlook is triggered by identifying the reminder category and the MSAccess macro is initiated which sends the emails then closes the Access application. This is done on a set scheduled recurrent basis as set for this Outlook reminder task.
The only issue we had was with the following line
mydb.Application.Run "MacroName"
the resulting error was rectified by
mydb.DoCmd.RunMacro “MacroName”
We now have a method of scheduling which works.
It would seem that when an Access VBA script, which includes sending an email is called from an OUTLOOK scheduled script it has no problem in completing the task, whereas, the exact same script actioned through Task Scheduler just does not complete.
Hope this helps others.
Related
Currently I am trying to run a SAS program using VBA. Using the SAS Add-In For Microsoft Office, I created a stored process that contains a generic code that creates a dummy table. Inside SAS EG, I am able to run the Stored Process normally, and also inside the Excel environment, using the InsertStoredProcess function of the SASExcelAddIn object. Regardless of the environment used to run my Stored Process, the behavior of the SAS Sessions are the same: one session is created when I start to run and another one is created during the process. However, that is where my problem comes. When the process finishes, I continue with the two sessions as active, and every time I try to run again my Stored Process, one new session is created over the ones that already existed. The sessions close only when I manually disconnect from the SAS Server I'm connected or when I close the Excel. Since my organization allows only three concurrent sessions, this is becoming a big problem for me.
I already tried to use the ABORT macro function inside my code, the rc=stpsrv_session('delete') command and delete the Stored Process from the Excel worksheet, and none of them solved my problem.
Any ideas of what I'm missing here? Is there a way to end the SAS Session after the Stored Process ends?
First of all, you shouldn't use VBA to do any of this. If in Office products, use VSTO and C#. I am in the throes of converting thousands of lines of VBA to C#/VSTO. VBA is very obsolete which is why the code is being converted.
Second, EG is built using C# so it is more natural to use. You can even create custom tasks using C# in EG.
You need to close out your sessions after they are started. See this post at SAS for how to close out your sessions in VBA: https://communities.sas.com/t5/SAS-Enterprise-Guide/Calling-SAS-through-VBA/td-p/79673
Again, you should stop using VBA and switch over. It will be much easier. VSTO is free and is made to interact with Office. Use Visual Studio to create your project. The C# code for working with SAS can be found using any of Chris Hemendinger's post (SAS community manager) or you can refer to links on my github repos here: https://github.com/savian-net
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.
I'm wondering if anyone here has experience with setting up a macro to run automatically at a given time... lets say 5AM.
There are some posts on mr excel but most of what I find is simply OnTime "x time" based code, and I'm unsure how this executes.
Do you have to open the sheet, run the macro and then expect it to run at the given time? Once it is open, will it run every day at that time or can you run it whenever?
You could
1] have Windows task scheduler open your workbook. Please see: http://windows.microsoft.com/en-us/windows7/schedule-a-task
2] and then create a function in your macro that launches your code when the book is opened. See http://www.mrexcel.com/forum/excel-questions/6122-run-macro-open.html for more info.
This seems to be what you want:
How can I Run Excel Files as a task or job?
Use the Windows Scheduler to schedule a task to open up the Excel file. You should then be able to use the Workbook_Open Event to do what you need with the file.
I'm trying to automate the security prompt in outlook when I try to send emails via a 3rd party software i.e SAS. What solutions are there? I've tried a VBA solution and reduced security to low on the tools - macros setting but no joy :(
Aside from the first warning message that an external program is trying to access Outlook you can save drafts of messages without any hassle (at least using VBA). I used this to produce whatever emails I needed then ran a seperate macro INSIDE Outlook to send all the drafts.
Or you could use an Outlook macro to communicate with the external software and send it's own emails based on an output.
I have an Outlook 2003 macro written in VBA.
I would like to schedule it so that it automatically runs at a certain time, say 01:00. The PC is always logged on.
I couldn't find anything which suggests how to do this.
You could create a scheduled task on the PC to run daily at the specific time, and use the Outlook Command Line Switch to start the program and call your macro e.g:
"C:\Program Files\Microsoft Office\Office11\Outlook.exe" /autorun macroname
Update:
You may be able to use an API call to start a timer to run in the background of outlook, you could combine this with the VB Now() command to get the current time and if greater than your scheduling time you could trigger your macro, the API example can be found here:
http://www.outlookcode.com/threads.aspx?forumid=4&messageid=22831
http://support.microsoft.com/kb/237913/EN-US
This article says it can't be done unless you rewrite it to use CDO.
Sorry.