Hello Beta,
There are a few ways to do this, but perhaps this is the most simple
to implement. I will describe first how to put the macro into your
"Normal" document (so it is available whenever you run MS Word). You
could save this to another file if desired (so you can share it with
other users); select the other file if you want to do this.
Step 1 - Create the macro
Open Microsoft Word.
Select Tools -> Macro -> Visual Basic Editor
At this point, you should get a window labeled "Project" - Normal. You
may get other windows if you have ever used Visual Basic before.
Select the item at the top of the window labeled "Normal".
Select Insert -> Module
You should now see a window labeled "Normal - Module1 (code)" [or
similar]. Paste the following code into that window.
' Save all as text - save all open documents as text files
Sub SaveAllAsText()
Dim a$
For Each adoc In Documents
a$ = adoc.Name + ".txt"
adoc.SaveAs FileName:=a$, FileFormat:= _
wdFormatText, AddToRecentFiles:=False
adoc.Close
Next adoc
End Sub
To explain the code above, it declares a string variable A$. Then for
each document that is currently open,
- sets A$ to (current name).txt
- saves the file with that name, text format, and does not add the
file to the "Recent Files" menu
- closes the file
When all files are processed, the macro stops.
Select File -> Save Normal
Select File -> Close and Return to Microsoft Word
At this point, you can open a few files to test it.
Step 2 - When it is time to convert files...
Select the files in the finder & open w/ Microsoft Word
Select Tools -> Macro -> Macros
A window will appear, select SaveAllAsText and then Run. The macro
will then process each open document and quit. You can then confirm
the conversion by opening the files or browsing the directory with the
finder.
Step 3 - Making it "better".
Just a few hints on how to write these kinds of macros (which work in
a similar manner in Excel and Powerpoint) are:
- In Word, select Tools -> Macro -> Record Macro, then record a few
steps, and then stop. Go into Word Basic to see what was recorded. Cut
/ paste the steps into another macro to have it do what you want to.
- In Visual Basic, select View -> Object Browser. This brings up a
tool that can describe the "objects" (such as Documents) defined by
Word. Type a phrase into the field to get a list of objects, methods,
and fields that match that phrase. Select one & then [?] to go
directly to the help on that topic. Be sure to look at the examples
for suggestions on using this. Do this for Documents for the idea on
the for loop on open documents.
- In Visual Basic, select View -> Immediate Window. This brings up an
empty window. You can enter print statements here to examine variables
you define or the values in Word Objects. Something like
print Documents.count
will display
1
if you have just one open document.
- Start with something simple. Add steps to it after each part is
"correct". There is a debugger as well, click on the left side of the
code window to set a "stop sign" on a line. That will stop your macro
before running that statement and allow you to print values (in the
immediate window) and make some minor fixes if needed.
I tested this with both Word 98 and Word X - it should work the same
on 2001. If not, tell me what you see so I can help diagnose the
problem.
--Maniac |