Solved

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

Posted on 2016-09-17
15
32 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
  • 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
 
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 27

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 27

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now