Macro help

R

RobertB.

I recorded a simple macro that opens a file, strips out page breaks, and
save the file as Unicode text in the same directory it started from.
However, I have several dozen files on which I'd like to perform the
same operation. The files all have the same file name structure, which
is "file.SFT (Word6)". The files will be saved as "file.txt".

Can I get word to open all the files in this folder, perform the find
operation and save the files without my intervention? So that I can end
up with: file1.txt, file2.txt, file3.txt (where file1, file2, file3, ...
filen represent the actual file name (before the period) found before
the conversion? Example, CODE.SFT (Word6) would become CODE.txt (a
Unicode file) and the macro will do this for all the files in a given
directory.

Is this possible?

What I recorded is:

Sub WordtoUnicode()
'
' WordtoUnicode Macro
' Macro recorded 12/10/05 by Robert
'
Documents.Open FileName:="CHEM.SFT (Word6)",
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.SaveAs FileName:="CHEM.txt", FileFormat:= _
wdFormatUnicodeText, LockComments:=False, Password:="",
AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, HTMLDisplayOnlyOutput:=False
ActiveWindow.Close
End Sub

But obviously this will only work on the file I recorded it for. I'm
assuming I cannot simply replace the first part of the name with a wild
card.

robert
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Robert:

Yes, it can be done. It's quite advanced VBA or AppleScript programming.

For "several dozen" files, dare I assume a number less than a hundred files?

If so, it will be far quicker for you to open the files individually, search
them and save them. Word will open between 10 and 20 files at once,
depending on your system and available memory. You'll have it done by
tomorrow!

Creating this macro would take you a couple of weeks, assuming you are a
competent programmer and I sent you a working example :)

Cheers


I recorded a simple macro that opens a file, strips out page breaks, and
save the file as Unicode text in the same directory it started from.
However, I have several dozen files on which I'd like to perform the
same operation. The files all have the same file name structure, which
is "file.SFT (Word6)". The files will be saved as "file.txt".

Can I get word to open all the files in this folder, perform the find
operation and save the files without my intervention? So that I can end
up with: file1.txt, file2.txt, file3.txt (where file1, file2, file3, ...
filen represent the actual file name (before the period) found before
the conversion? Example, CODE.SFT (Word6) would become CODE.txt (a
Unicode file) and the macro will do this for all the files in a given
directory.

Is this possible?

What I recorded is:

Sub WordtoUnicode()
'
' WordtoUnicode Macro
' Macro recorded 12/10/05 by Robert
'
Documents.Open FileName:="CHEM.SFT (Word6)",
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveDocument.SaveAs FileName:="CHEM.txt", FileFormat:= _
wdFormatUnicodeText, LockComments:=False, Password:="",
AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, HTMLDisplayOnlyOutput:=False
ActiveWindow.Close
End Sub

But obviously this will only work on the file I recorded it for. I'm
assuming I cannot simply replace the first part of the name with a wild
card.

robert

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
R

RobertB.

Hi Robert:

Yes, it can be done. It's quite advanced VBA or AppleScript programming.

Oh. 8-(

For "several dozen" files, dare I assume a number less than a hundred files?

Less than a hundred. Not sure how many exactly.
If so, it will be far quicker for you to open the files individually, search
them and save them. Word will open between 10 and 20 files at once,
depending on your system and available memory. You'll have it done by
tomorrow!

I did most of them already, but it's not all that efficient.
Creating this macro would take you a couple of weeks, assuming you are a
competent programmer and I sent you a working example :)

Hmm. I thought it would be a five-minute job for someone familiar with
VBA. Sounded pretty repetitive to me. Open file. Save as. Et cetera.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Robert:

No, it's a four- or five-hour job even for someone who is very familiar with
VBA.

I could "sell" you one, but the one I have works only on the PC. I would
have to spend a day futzing around to make it work on the Mac. The Mac uses
a different function to walk a directory list.

It's quite "do-able", but it's beyond the limit of what I am prepared to
offer without charge. Doing this stuff is what I do for a living -- if you
figure out how to get free samples out of your bank, get back to me and I
will revise my policy :)

Sorry...


Oh. 8-(



Less than a hundred. Not sure how many exactly.


I did most of them already, but it's not all that efficient.


Hmm. I thought it would be a five-minute job for someone familiar with
VBA. Sounded pretty repetitive to me. Open file. Save as. Et cetera.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
R

RobertB.

Hi Robert:

No, it's a four- or five-hour job even for someone who is very familiar with
VBA.

No kidding. I thought this would be a standard routine. I suppose that
just entering *.doc in the Find box is not going to work. said:
have to spend a day futzing around to make it work on the Mac. The Mac uses
a different function to walk a directory list.
Oohhh.


It's quite "do-able", but it's beyond the limit of what I am prepared to
offer without charge. Doing this stuff is what I do for a living -- if you
figure out how to get free samples out of your bank, get back to me and I
will revise my policy :)

That's understandable. I wasn't expecting you to do it for free. Just
thought there was a simple answer and it was something I had overlooked
or could easily squeeze into the recorded code. I work freelance as well
and you'd be surprised how many people ask me to provide free samples of
my work. I don't always comply.

r.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top