Solved

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

Posted on 2016-09-17
15
55 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 28

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 28

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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