Jump to content
Macro Express Forums

Opening Multiple Word Files At Once.


lemonchicken

Recommended Posts

I am trying to figure out a stable way of opening multiple Word docs all at once. The macros I created checks a particular folder every 5 seconds to see if there are any Word docs in it. There could be one, five, ten...over one hundred! The problem is that the more files it has to open, the longer it takes to open all of them.

 

I currently have it set to count the number of Word Docs in the folder using repeat functin and then using that count in a formula I played around with to adjust the delay time so that it can complete opening the files. However, it is not perfect and sometimes does not compensate enough and it will "move on" before all the Word Docs are opened.

 

I'm hoping that there is an easier way to have the macro wait until ALL the Word Docs are opened.

 

Thanks!

Link to comment
Share on other sites

In the timing section check out the "Wait for Window Title". Also if you're interested look back thru the recent posts a I gave a guy my suggestions on monitoring folders. I have a large macro that monitors a folder for PDF files fro a fax machine and I think it will be about the same as what you are trying to do.

 

Also if you use any Repeat with Folder commands it's better to make a file list for comparison as the folder contents might change before it is done opening all the Word windows.

Link to comment
Share on other sites

Cory,

I saw the your post in regard to the "Repeat Untill %T1%<>%T1%. Interesting...approach it from opening a file one at a time. Might work for me but might be too slow when there are numerous files to open.

 

The Macro you mentioned about your PDF macro for Faxes sound promising. When it finds the folder has files in it, does it open them all at once? And if so, who do you compensate for the amount of time it takes to open all the files?

Link to comment
Share on other sites

I think you're seeing yet another post. There is one that goes into detail about different methods of monitoring folders.

 

My fax macro uses file manipulation to keep things straight. When a fax arrives the MFP pushes a PDF to the 'received' folder. Once every minute the macro fires and check to see if the domain user is the designated fax monitor. It then opens the first file in the folder with a Repeat with Folder > Break > End Repeat. Then it launches the PDF file directly using the Launch only command and since there is a file association to PDF one can simply use the file name with path. It's just like you typed it in the "Run" window. I wait for the widow to appear and become ready and once it does I give the user a series of prompts for things like who the recipient is, notes, of if they just want to delete it. Once they click OK an email is sent out to the selected users with a link to the file's final destination. Then I close the document (not Acrobat because it takes FOREVER to load on some machines) and wait for the file to become ready again. It's very useful to use the status of the system file locks in macro timing. In now minimizes Acrobat and moves the file to another folder called "Notified". Then the whole thing repeats until there are no more files.

 

Repeat with Folder in cases like these is problematic. For instance if you want to rename a bunch of files you're going to have fun. ME revaluates the folder contents every time it runs so unless all of your renames are alphabetically later you will get some wild results. In the fax monitor I found it easier to push the file to anther folder. In other cases I needed to keep the files in the same folder so in that case I do a Repeat with Folder but write the folder listing to a variable. Then I do a repeat again and chew thru that variable until it's empty. You can do the same thing by using the Variable Text Modify - Append to File option with a carriage return and then use the Repeat with Text File. It's easier to understand but I have this thing about avoiding disk writes.

 

If you can't move the files and need to monitor for any change things get a lot more difficult but not insurmountable. You need to create a list and save it somewhere for the subsequent time the macro runs. Then you create a new list and check each item to see if it exists in the old list. Then you need to compare the other way. It's not too hard but you need to get your logic down pat. This is why a file move is a lot easier!

 

To directly answer your question I think opening one document at a time might not be the best way. It depends on what you're doing with them. If it requires user input I'd suggest doing it one at a time. If you just want to open them to marvel at the cascading windows or something I can think of another way.... When you search for new files or whatever and you have several candidates to launch there is a way to avoid all your timing issues I think. Simply write all the file names with path to a batch file. Then run the batch file and delete it! You could even wait for the window title of the last file since Word puts the file name in the title bar.

 

Maybe if you describe more what it is you're doing I could give a better answer. There's a lot of 'it depends' in here.

Link to comment
Share on other sites

Cory,

 

Thanks for your input. The last couple of suggestions seem promising. Couple of questions though:

 

One: When you say "write the name of the file to a path of a batch file, run the batch file and then delete", can you elaborate?

 

 

Two: Waiting for the last Word Doc title to appear using T2, or whatever, looks promising too but doesn't it also take the file ext. DOC? The title does not include the ext so how do you eliminate the ext?

 

Thanks again Cory

Link to comment
Share on other sites

Cory,

 

Never mind about the ext question. It must be a setting in Office that I have to adjust to show the full path of the file in the title. Should be simple.

 

I tell ya, sometimes the things that we make into a mountain, really turns out to be a little mole hill! I think waiting for the last file title window to open usin %Tn% will work perfectly.

 

Thanks again Cory!

Link to comment
Share on other sites

I'll split this into two responses. First the last.

 

If you have a file name in T1 for example all you need to do is to eliminate the ".doc". Now you could count the number of characters and copy part but that’s a lot of extra work. Check out the “Variable Set From File”. Here you can grab any part of a file’s name. So stick %T1% the top field and click on the “Get file path” section on the right. Check only the filename box and choose T1 as the var. This will grab just the name without extension and stick it back in the T1 var. If you still need the T1 var for something don’t recycle and use T2 or whatever.

 

 

<VFFILE:1:F:1:F:1:T:1:F:1:%T1%>

Link to comment
Share on other sites

For the batch file…

 

I don’t know how much you know about batch files so forgive me if I cover something you already know. I assume you know what the command prompt is. And I assume you understand you can type commands in and do things there. Well along with being able to copy files and such you can also launch documents. Let’s say you have a file c:\test.doc. Well in the command prompt you could type just that and Word will launch with that file. Now a batch file is a way in Windows of saving a series of commands in a simple text file with a .bat extension. You can double click on it or run it like a program and it will open a command prompt and execute the commands just like you typed them in. So if you have a file that looks like this:

 

C:\document1.doc

C:\document2.doc

C:\document3.doc

C:\document4.doc

C:\document5.doc

C:\document6.doc

C:\document7.doc

 

And save it as test.bat it will launch the seven documents in Word.

 

You can use the Variable Modify String command and Option 2 tab to write the file names and path to a temporary batch file called test.bat. Don’t forget to add a carriage return on each one. Once the bathc file is written use the Program Launch command to run it. Then write a command to delete the batch file.

 

Does this help?

Link to comment
Share on other sites

OK, waiting for %Tn% title to appear seems to work ok but for some reason, if there are quite a few documents to open, say 75, it starts moving on at about 35 files open without waiting for the last file to open. I've even got it set to wait indefinitely.

 

Is it somehow failing in the Repeat with Folder because there are too many?

Link to comment
Share on other sites

What the heck are you doing? <g> In general I would avoid opening that many Word docs at a time. Bad mojo. Whatever it is you are doing can't you process them one at a time?

 

To answer your question I don't know. In my book you've gone off the map and "Here there be monsters". My first impulse would be to figure a way to avoid opening an untold number of documents at once.

 

Could you break your list up to do them in smaller batches?

 

My interest is piqued. What are you doing there?

Link to comment
Share on other sites

OK...here is a real dumb question.

 

Trying out the batch and I got it to enter the path name of all files needed to be opened. Everything looks good but when I run the batch, it only opens on word doc and won't open the next one until the previous one is closed. It has to be a Window setting somewhere. It won't run through the entire batch file and open all the files at once.

 

???????????????????

Link to comment
Share on other sites

Hmmm.... You're right. It only opens the first file. I had not tried this before with Word and you're right, it doesn't work. Sorry, bad advice. It works with other applications, evidently not with Word.

 

Still I go back to asking about why you need to open all of them at once.

Link to comment
Share on other sites

It's weird because I tried it on a different machine and it opens all the word docs at once. It has to be some kind of Windows setting or something in Office. Haven't been able to figure it out yet. Otherwise, this has the potential to work nicely.

 

Getting the last file name off of %Tn% seemed like it would work well too but for some reason or another, even though I tell it to wait until the last file name title appears, it keeps moving on after about 35 files. Go figure?????

 

To answer your question, basically, the main Macro does this:

 

Checks a folder every few seconds to see if Word Docs have been added.

 

If so, it takes the Word Docs and moves it to another folder for processing.

 

Open all Word Docs (seems to be more efficient as far as time is concerned)

 

Take a Word Doc, correct a Margin Discrepency, save as a PDF to a shared directory, save as a TIFF to another shared directory, resave Word Doc with corrected margin and place in another shared directory. Thus it creates a PDF, TIFF and an updated DOC for each file and saves them to a shared directory that users can access.

 

Move on to the next Word doc for processing until all have been completed.

 

Check the main folder again for more docs. If not, wait five seconds and check again.

 

Macro set to start everyday at 6:00 and shut down at 20:00

 

There are other things it does on the side but basically the above is its main task. The tricky part is it needs to run everyday and mostly unattended so I had to work in many scenarios where it bombs out so that it can get itself out of it and restart. Has been a challenge but when it works it's pretty sweet. Files can get dumped in the folder as little as a few per minute upwards to 50 per minute so on peak times it is a pretty busy macro.

 

Thanks for all your help on this Cory. Much appreciated!

Link to comment
Share on other sites

Sounds like fun. A great application of ME. I was looking at this some more. I know on other machines multiple Word docs would launch. I think something in Vista may have changed. Might want to add a delay in between each link of the batch file. That might help.

 

As a practical matter I would not open all the Word documents at once. I have something similar in my fax macro. An MFP dumps a PDF in a folder and I open it up and look at it and email selected users a notification and move the file to a ‘notified’ folder.

 

My approach is to schedule a macro to run every 60 seconds. It does a…

 

Repeat with Folder (T1)

Break

Repeat End

 

To get the first file name. I then opens the PDF and prompts the user, enters metadata and then moved the file and email an alert. Then this whole thing is in a repeat until T1=”” (Blank). So you see it fires every minute and repeats as many times as there are files. Even if the folder contents change in the mean time the macro will pick it up. Works slick.

 

I would recommend you consider this approach instead of launching a gazillion Word documents all at once.

Link to comment
Share on other sites

Cory,

 

I'm ALMOST there! Soooo close I can taste it!

 

Opening them up one at a time seems to work well and I've been actually able to increase the speed of the Macro Playback which compensates for the slight increase in time it takes to open files one at a time.

 

One annoying issue I can't seem to figure out. When it runs the Repeat on Folder to grab the first file name to process, it looks like it grabs them in alphabetical order no matter how the files are arranged in the folder. I need it to open in order of Date Modified so it will process the oldest file first. I have the folder set to rearrange the files by Date Modified but the macros still seem to go by the default of Alphabetical order. This could be a potential problem because it is possible for a file to take a long time to process depending on the file names.

 

Any ideas?

 

Thanks,

Lemon

Link to comment
Share on other sites

The Repeat with Folder command asks Windows for the files. Windows sends them in alphabetical order on Windows XP/2000/NT. It sends them in the order they appear on the hard drive (seemingly random) for Windows 98/Me/95. I do not know what order they appear for Windows Vista but I expect it would be the same as Windows XP.

 

The order they are presented in Windows Explorer is irrelevant to the order they appear to another application.

 

I think it would be possible to process them in date/time specific order but it will take some effort. Maybe something like this will work:

 

- Repeat with Folder.

- Get file name and date/time stamp for the file.

- Write the Date/Time stamp followed by the file name to a file. (I would suggest .csv format)

 

- Sort the content of the file (that is why the Date/Time Stamp was written first)

 

- ASCII Text File Begin Process (using the sorted file)

- Do your macro stuff here

- ASCII Text File End Process

Link to comment
Share on other sites

Naw, it's simpler than that, you don't need to sort since we only need one file.

 

BTW Kevo, Vista seems the same.

 

What I would do is a repeat with folder. Extract the date time info and run thru every file. For each one get the date and compare. If the date is older push it to a 'bubble' variable. Then this will be used for comparison on each subsequent iteration. IOW if the file date is older move it to the bubble. In the end you will have the oldest file. PG Macros function library have date comparisons pre-built for you.

Link to comment
Share on other sites

Thanks for your suggestions! I am currently trying the method of opening one at a time and stripping the timestamp on a Repeat Folder to find the oldest one. So far so good.

 

I currently have it running on the backup machine. I will change it on the primary machine next. Keeping my fingers crossed.

 

THANKS ALL!

 

Cory: Thank you especially!!!!!!

 

Lemon.

Link to comment
Share on other sites

No problem, I enjoy it and I learn a trick or two from you all. In fact you were teh one who got me thingking aobut the right click and I put it out there and Paul came up with that awesome tutorial. Now I have a cool new trck I would have never though of before.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...