Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2016-09-17
15
Medium Priority
?
467 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
14 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 31

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 31

Accepted Solution

by:
serialband earned 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

580 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