Solved

VBA Macro to convert thousands of .doc files to .docx (Word 2011 for Mac)

Posted on 2016-09-17
15
180 Views
Last Modified: 2016-10-16
Hello,

I need a VBA Macro for Microsoft Word 2011 (Mac) that converts thousands of files in a given folder from .doc format to .docx format.  The converted .docx files must be in full, true XML format (not "Compatibility Mode").  The script must cycle through the folder, converting 1 (one) file at a time, until all files have been converted.  The faster, the better.  There are 3 (three) additional requirements:

1.  The macro must convert without prompting -- or skip -- any one of the .doc files that does not have recognizable encoding.

2.  Formatting, tables, images, lists, etc. must not be lost upon conversion.

3.  I need very specific, step-by-step instructions on exactly how to install and use it, because I have zero experience with that.
0
Comment
Question by:Jay Bren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2
15 Comments
 
LVL 53

Expert Comment

by:strung
ID: 41803303
0
 

Author Comment

by:Jay Bren
ID: 41803311
@strung:  I already tried the demo of that software.  It is useless because the new .docx files lost most formatting and all tables, images, lists, etc.
0
 
LVL 53

Expert Comment

by:strung
ID: 41803313
Have you seen this article about a Microsoft tool to do the conversion?

https://blogs.msdn.microsoft.com/ericwhite/2008/09/18/bulk-convert-doc-to-docx/
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:strung
ID: 41803316
0
 

Author Comment

by:Jay Bren
ID: 41803317
@strung:  I need a Mac-specific Macro.  About 95% of the so-called "solutions" online were written for Windows (and almost all of them are very outdated).
0
 
LVL 29

Expert Comment

by:serialband
ID: 41803322
You might be able to use an AppleScript and modify the doc/docx to pdf on the following pages.
https://onabai.wordpress.com/2012/07/10/convert-word-files-docdocx-to-pdf-in-osx/
http://hints.macworld.com/article.php?story=20110605113316760

Possibly like this:
property theList : {"doc"}
on run {input, parameters}
    set output to {}
    tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
    repeat with x in input
        try
            set theDoc to contents of x
            tell application "Finder"
                set theFilePath to container of theDoc as text

                set ext to name extension of theDoc
                if ext is in theList then
                    set theName to name of theDoc
                    copy length of theName to l
                    copy length of ext to exl

                    set n to l - exl - 1
                    copy characters 1 through n of theName as string to theFilename

                    set theFilename to theFilename & ".doc"

                    tell application "Microsoft Word"
                        set default file path file path type documents path path theFilePath
                        open theDoc
                        set theActiveDoc to the active document
                        save as theActiveDoc file format format DOCX file name theFilename
                        copy (POSIX path of (theFilePath & theFilename as string)) to end of output
                        close theActiveDoc
                    end tell
                end if
            end tell
        end try
    end repeat
    tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath
    return output
end run

Open in new window

0
 

Author Comment

by:Jay Bren
ID: 41803345
@serialband:  It works like a charm for converting batches of .doc to .pdf, without losing any formatting.  However, when I try your edited version for .docx conversion, I get this error:

The action “Run AppleScript” encountered an error.

I see no reason why it wouldn't work if I can just figure out what , exactly, the "error" is and fix it.  :)
0
 
LVL 53

Expert Comment

by:strung
ID: 41803350
Shouldn't the line

set theFilename to theFilename & ".doc"

read

set theFilename to theFilename & ".docx"

?
0
 
LVL 53

Expert Comment

by:strung
ID: 41803354
Here is another alternative script:  https://discussions.apple.com/thread/3026861?tstart=0
0
 
LVL 53

Expert Comment

by:strung
ID: 41803356
0
 

Author Comment

by:Jay Bren
ID: 41803359
Yes, @strung, I believe that @serialband meant to type ".docx".  I changed it to ".docx" for my testing, but I received the same error message.
0
 
LVL 53

Expert Comment

by:strung
ID: 41803361
Have you tried stepping through the script to see what line generates the error?
0
 
LVL 29

Accepted Solution

by:
serialband earned 250 total points
ID: 41803364
Strung is correct.  I thought I typed docx there, but maybe got autocorrected or something.

Is there a more specific error that indicates which line it failed on?  Maybe you can open the script with Script Editor and run it through that and see.

Maybe also change line 26
save as theActiveDoc file format format DOCX file name theFilename

Open in new window


To
save as theActiveDoc file format format "Word Document (.docx)" file name theFilename

Open in new window

0
 
LVL 53

Assisted Solution

by:strung
strung earned 250 total points
ID: 41803370
The link here:  https://www.reddit.com/r/applehelp/comments/3qd9az/applescript_to_batch_convert_doc_to_docx/

has script almost identical to the one you and Serial Band are working on, but instead of

"save as theActiveDoc file format format DOCX file name theFilename"

it has

"save as theActiveDoc file format format document file name theFilename without maintain compatibility"
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question