PDA

View Full Version : conversion macro



dqasem
03-11-2005, 05:09 AM
Hi everyone,


I need two macros for Microsoft Word 2004. One that tranverses through a directory and its subdirectories and converts every file into a txt document, saving it into separate directory, maintaining folder structure if possible. Otherwise it just needs to save as txt and and add the extension .txt. This macro must overcome the dialog that prompts the user to lose formatting, etc.

The other macro is a bit more complicated. It has to tranverse through a directory and its subdirectories and open txt files, run a specific macro on each file, change the font to arial, and then save the file as a word document. Depending on what is done in the previous macro, it might have to be renamed. Again, folder integrity must be maintained. Finally, this needs to work on Mac Word 2004 as the characters that are being converted are MAC ANSI.

Thanks for all your help

mdmackillop
03-11-2005, 06:41 AM
There's a maco here http://www.vbaexpress.com/kb/getarticle.php?kb_id=245 that will do the looping. It would seem easier to make a copy of your folders and files into the "new" location, and then run the code on these files.

Change Sub OneType to look for *.doc files
Add the line DoConvert strFolder, strFileName
where indicated to the looping macro to call the next routine

Sub DoConvert(strFolder, strFileName)
'
' Macro1 Macro
' Macro recorded 11/03/2005 by malcolm
'
Dim MyFile As String
ChDir strFolder
MyFile = Left(strFileName, Len(strFileName) - 4)
Documents.Open FileName:=strFileName

Application.DisplayAlerts = False
ActiveDocument.SaveAs FileName:=strFolder & "\" & MyFile & ".txt", FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
Debug.Print ActiveDocument.FullName
ActiveDocument.Close
Application.DisplayAlerts = True

End Sub


Sorry, no time for the second bit just now.

BlueCactus
03-11-2005, 01:56 PM
Not sure if the file traversing bit will work on Mac Word. Maybe you'll get lucky. If necessary, you can use AppleScript to return the folder lists. You can call Applescript from VBA using result = MacScript(script as string)

Multiline scripts can be built as "blah-blah" & chr(13) & "blah" etc...

If AppleScript returns a list, result will be "item1, item2, item3, ..." etc...

Don't have time to do this myself, but I'd like to see the finished result.

BTW, be careful as this is likely to involve recursive code.