+ Reply to Thread
Results 1 to 6 of 6

Can I trigger a VBA script without pausing Outlook for the duration?

  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    Manchester, GB
    MS-Off Ver
    365,2016,2013,2010,2007,2003
    Posts
    17

    Can I trigger a VBA script without pausing Outlook for the duration?

    This might seem a little backwards, but I've spent the last 9 months developing a complicated system of very effective VBA scripts for Outlook automation, but now I'm asking a fairly simple n00b question.

    Can I have Outlook run a script, but leave Outlook usable whilst running it?

    Background: despite having the VBA code for Event triggers to launch scripts when an email arrives, I've not found it to be reliable enough (admittedly I've not tried it again since I upgraded from 2003 to 2010 - so I might try it again). So instead, I use an Outlook Rule to trigger the script when an email arrives with certain keywords (e.g. when an attached report arrives with AUTORUN in the mail subject). But this approach hangs Outlook throughout the script, and if something is taking longer than expected to run, e.g. if a shared drive is particularly slow (or as happened last week, if I've made a mistake in the setup and I'm running an Update query that takes 6 hours to run!!), I've rendered Outlook unusable for a whole day. I don't know if switching to Event triggers would even change that.

    I've thought about creating a new Outlook.Application instead of using the intrinsic Application object but my experience with Excel VBA tells me that that wouldn't make any difference. However, with no formal training in VBA maybe I've missed a trick there too...!!

    I've also thought about manually starting a new session of Outlook but I'm worried that'll just start running the same scripts twice......

    I've also just thought that maybe using Shell is the answer...?

    Help appreciated, and sorry if I've posted this in the wrong support forum
    Last edited by baldmosher; 08-05-2013 at 05:31 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Can I trigger a VBA script without pausing Outlook for the duration?

    Event triggers would still hang outlook, vba works by running one command at a time, you can't "multithread" (run two scripts at the same time). There are some examples of ways to simulate multi-threading but I don't think that would work very well for your purposes.

    I'd approach this by writing scripts as a console application/.exe and then calling these scripts from within outlook. I think that would allow you to end the macro in outlook and stop it hanging.

    Also - now then mosher.

    Edit: If you manually started a new instance of outlook that would be responsive - I'd suggest trying it to see if it called the same script again.
    Last edited by ragulduy; 08-05-2013 at 05:28 AM.

  3. #3
    Registered User
    Join Date
    09-27-2012
    Location
    Manchester, GB
    MS-Off Ver
    365,2016,2013,2010,2007,2003
    Posts
    17

    Re: Can I trigger a VBA script without pausing Outlook for the duration?

    Heh, small world!

    Starting a new Outlook session seems to have started running more scripts automatically - for some reason my first attempt of running "outlook /safe" didn't work - as the new session is not responding. However, judging by what Firefox is downloading, it doesn't appear to be running the same scripts, which is a relief, so I guess it might well chunk through the triggers in the inbox a bit quicker as a result. Or maybe it's just hanging whilst the first session is running VBA.

    I'm intrigued by what you mean by "writing scripts as a console application/.exe and then calling these scripts from within outlook"? Do you mean running via Shell cmd? (I can see how that'd work as for another macro I have to use ShellAndWait to pause VBA while 7zip command line finishes its business.) Or if I've not grasped that, any good resources to start me off with that?

    EDIT: to be clear, I think what I'm doing that might only be of limited use. My process is as follows
    1. save attachment/download CSV via hyperlink in email
    2. start Excel, open WB, macro to update database from new CSV and push out reports runs on Workbook_Open event, then closes Excel when finished
    3. file email in specific folder

    So essentially I want to drop back into Outlook and do step three immediately after launching step 2
    Last edited by baldmosher; 08-05-2013 at 05:44 AM.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Can I trigger a VBA script without pausing Outlook for the duration?

    Yes, shell would be one method, I was thinking was to instead of writing a macro, write a .exe console application using something like vb.net then have say, a folder C:\Scripts where you save the various bits of code for step 2. Then you could use:
    Please Login or Register  to view this content.
    I did a quick test and this should allow you to continue using outlook. However, there are a few other problems you might run into, for example, trying to open the same excel workbook from two different instances of the same script.

  5. #5
    Registered User
    Join Date
    09-27-2012
    Location
    Manchester, GB
    MS-Off Ver
    365,2016,2013,2010,2007,2003
    Posts
    17

    Re: Can I trigger a VBA script without pausing Outlook for the duration?

    Thanks for testing, I think that approach would be OK for 95% of my scheduled triggers. (Each schedule only triggers one macro update, and so sharing violations from duplicated triggers would be a note of caution for me to fix that.)

    It would also have the added bonus that an error in the external workbook macros won't stop everything else from downloading. The schedules run on Sunday, which means I should turn up for work on Monday with everything downloaded and just the macros in error to deal with -- currently I come in at 9am, fix an error, and then have to forego the machine and hammer the office network pipe for 4 hours while the rest of the scheduled downloads complete.

    Looks like I will need to learn vb.net how exciting!

  6. #6
    Registered User
    Join Date
    09-27-2012
    Location
    Manchester, GB
    MS-Off Ver
    365,2016,2013,2010,2007,2003
    Posts
    17

    Re: Can I trigger a VBA script without pausing Outlook for the duration?

    Don't you just love Microsoft, it's impossible to find Visual Studio Express 2010 anywhere on microsoft.com and all their summary blurbs for VSE2012 only mention Windows 8 platform. Well let's hope it'll run on Windows 7.

    EDIT: yeah it will, apparently

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VB Script to Pull Outlook Properties for List of IDs or Names
    By navs8603 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-24-2013, 02:18 AM
  2. [SOLVED] Formula: To calculate duration between two times, if duration is over 6hours subtract 30mi
    By MattBarnes7 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-11-2013, 03:22 PM
  3. Script to fetch PDF file from Outlook and process it to Excel.
    By neaz1st in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-14-2012, 01:31 PM
  4. Pausing Code to Trigger Other Events
    By SDruley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2011, 01:53 PM
  5. [SOLVED] Reply to outlook email from excel script
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2006, 12:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1