VBA - wait for other program to close

Phantek

New Member
Joined
Apr 11, 2011
Messages
10
Is there a way to get my vba code in Access to wait until Microsoft Word has finished closing before it executes the next command?

I have set up some code to open up a Word file, fill in form data, convert the file to pdf, and then close down word. The problem is that I then need to open up a different word file and do the same thing with different data.

The issue is arising that while the first file is closing, the second one attempts to open up too quickly. I am getting an error message saying that normal.dot is already in use. Everything is fine if I build-in a timed delay in the code, but these timed delays can be unreliable.

Any idea how I can get my code to wait until the first instance of Word is closed before continuing? Alternatively, is there a way to perform the tasks with two open Word documents without them conflicting with one another?

Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top