Avatar of Jay Bren
Jay Bren

asked on 

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

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.
VBAMac OS XMicrosoft WordVB ScriptVisual Basic Classic

Avatar of undefined
Last Comment
strung
Avatar of strung
strung
Flag of Canada image

Avatar of Jay Bren
Jay Bren

ASKER

@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.
Avatar of strung
strung
Flag of Canada image

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/
Avatar of Jay Bren
Jay Bren

ASKER

@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).
Avatar of serialband
serialband
Flag of Ukraine image

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

Avatar of Jay Bren
Jay Bren

ASKER

@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.  :)
Avatar of strung
strung
Flag of Canada image

Shouldn't the line

set theFilename to theFilename & ".doc"

read

set theFilename to theFilename & ".docx"

?
Avatar of strung
strung
Flag of Canada image

Here is another alternative script:  https://discussions.apple.com/thread/3026861?tstart=0
Avatar of Jay Bren
Jay Bren

ASKER

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.
Avatar of strung
strung
Flag of Canada image

Have you tried stepping through the script to see what line generates the error?
ASKER CERTIFIED SOLUTION
Avatar of serialband
serialband
Flag of Ukraine image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of strung
strung
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo