+ Reply to Thread
Results 1 to 3 of 3

Pause Excel macro until MYOtherFile.vbs is finished

  1. #1
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    Pause Excel macro until MYOtherFile.vbs is finished

    Hi all, the project I'm working on does the following:

    1. Runs company reports from Excel
    2. Saves the reports as MyFileXXX.xls
    3. Calls a .vbs script which opens Outlook new message, adds MyFileXXX.xls as an attachment then sends the e-mail

    My code is set to do this

    1. Saves the .xls file to my 'temp' folder
    2. Creates the new email (via vbs script) and adds the attachment
    3. Pauses for 10 seconds (to give the email chance to send)
    4. Moves the .xls file from 'temp' folder to 'proper' folder

    The problem I am having is that only very rarely the email is created but for some reason the attachment isn't successfully attached in that 10 second window. The 'Move File' code then moves the file. The email then looks for the file (but of course it is missing) and so sends the email without an attachment.

    Ideally, instead of me saying 'Pause for 10 seconds' - I'd like to be able to say. Pause until the vbs file has sent the email.

    Is there a way for me to check that the vbs script has finished?

    Thanks
    John

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Pause Excel macro until MYOtherFile.vbs is finished

    Hi, you could probably have the vbs script exit with an exit code that is passed as a parameter to Excel
    Use this exit code to check if the mail has been sent, you will need a loop in Excel which checks every 1 or 2 seconds until the exit code is received and depending of this code you do the next steps.
    Another way I used to to this was to have the vbs scrpt create a dummy file (no extension) named OK when it completed successfully en NOK if not
    Make sure the previous OK and NOK are deleted before the next vbs runs and just check if one of these files exist.
    O yes, and these files I created the %TEMP% folder
    Hope this helps you a little.
    You could also use Application.OnTime to run a macro to test and have Excel continue doing other things.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    Re: Pause Excel macro until MYOtherFile.vbs is finished

    Hi Keebellah, thanks very much for the reply. I've had a little look into the exit code but feel that creating an 'OK' file as you suggested would be the best way to go about it.

    thanks again for the reply and the great response :-)

    John

+ 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. [SOLVED] Excel Macro Advancing before Solver is finished
    By jdpcbs in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-28-2014, 09:57 AM
  2. creating a pause in an excel macro
    By fbjnail1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-15-2013, 01:26 AM
  3. Pause excel macro code while application is processing
    By rschimmel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2013, 08:56 PM
  4. [SOLVED] Is it necessary to pause Macro for Excel to finish Autocalculation
    By nested.if1@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2012, 06:00 AM
  5. Pause Macro commands to allow Excel formulas to run
    By simpson11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2012, 05:02 PM
  6. msg box to show excel finished calculating after macro run
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2010, 09:43 AM
  7. Pause Excel Macro
    By Ollie in forum Excel General
    Replies: 3
    Last Post: 06-14-2006, 02:10 AM
  8. Replies: 1
    Last Post: 05-05-2006, 01:20 PM

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