June 14th, 2007

How Can I Change the Default File Save Format in Microsoft Word?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I’m running Word 2007, but most of my colleagues are still running Word 2003. Is there a way I can use a script to change the default file type when saving documents in Word? I’d prefer that, by default, documents are saved in Word 2003 format rather than Word 2007 format.

— PJ

SpacerHey, Scripting Guy! AnswerScript Center

Hey, PJ. You know, we’re nearing the mid-point for the month of June, which means that time is beginning to run out for the TechEd Challenge. If you somehow missed the Challenge announcement, it’s a fun little competition involving a word puzzle very similar to those found in Dr. Scripto’s Fun Book, something the Scripting Guys handed out at TechEd. (Actually, now that we think about it, it’s exactly like one of the puzzles found in Dr. Scripto’s Fun Book.) The premise is simple: we give you a bunch of letters and you try to form as many VBScript functions as you can, using only the letters provided to you. The object of the game? Use as many letters as you can, thereby earning as high a score as you can.

And why would you even want to earn as high a score as you can? That’s easy: the top 5 scorers will all win a Scripting Guys Gift Pack, a veritable cornucopia of prizes including:

A Dr. Scripto bobblehead doll

A Scripting Guys T-shirt

A Script Center coffee mug

Your very own copy of Dr. Scripto’s Fun Book

$150 million in cash (Editor’s Note: No, not this.)

Note. Needless to say, the $150 million in cash falls into the category of “while supplies last.” In all honesty, your Gift Pack probably won’t contain $150 million in cash. But we’ll see what we can do.

Scratch that: the Scripting Editor just informed us that we won’t “see what we can do.” Instead, we won’t do anything at all. So, sorry, no cash. Please direct all your angry emails to the Scripting Editor and not to the Scripting Guy who writes this column. After all, he’s the nice one who’s only trying to thank everyone for the support you’ve given us over the years.

And yes, we know: not everyone is good at word puzzles. (Did we mention that Scripting Guy Jean Ross tried the challenge herself and scored 116? We thought that was a pretty good score, at least until we saw the scores turned in by everybody else in the world. Wow.) But that’s OK; just send in an entry of some kind (even if you don’t get a single point) and you’ll be eligible to win a Dr. Scripto bobblehead doll. Sometime in July we’ll toss all the entries received into a hat, draw 10 names, then send each of those people a bobblehead.

We’ll also send each of those people $150 mil – um, never mind. We’ll just send them a bobblehead.

But don’t panic: you have until the end of the month, so there’s still plenty of time to enter. (If you’ve already entered, we’re going to start scoring entries – and posting results – either today or tomorrow.) In the meantime, we have another challenge that needs tackling: changing the default save format in Microsoft Word 2007.

Let’s start by taking a look at a script that displays Word onscreen and then changes the default save format. We’ll then show you a variation of this first script, a variation that makes this change without anything appearing to happen; under that script, Word starts, the default save format is changed, and then Word exits, all without anything appearing on screen.

But first things first:

Set objWord = CreateObject(“Word.Application”)
objWord.Visible = True

objWord.DefaultSaveFormat = “doc”

Believe it or not, that’s the entire script. (One of the interesting things about scripting is that tasks that sound hard are often ridiculously easy, whereas tasks that sound ridiculously easy are, well ….) Regardless, we really don’t do much work here. (Scripting Guys trivia: Interestingly enough, that exact phrase appears throughout our annual performance reviews.) We start off by creating an instance of the Word.Application object, and then setting the value of the Visible property to True; that gives us a running instance of Microsoft Word that we can see onscreen. We then use this single line of code to change the value of the DefaultSaveFormat property to doc, which just happens to represent the Word 2003 document format:

objWord.DefaultSaveFormat = “doc”

And that’s it. Suppose you start a new document and then go to save the file. Take a peek at the default file format that appears in the Save As dialog box:

Microsoft Word

Pretty slick, huh?


If you’d just as soon this happen automatically, without Word ever appearing on screen, then use this script instead:

Set objWord = CreateObject(“Word.Application”)

objWord.DefaultSaveFormat = “doc” objWord.Quit

This is pretty much the same script, with two exceptions. First, Word runs in the background, without ever appearing onscreen; that’s because we never set the Visible property to True. Second, we call the Quit method at the end in order to terminate our instance of Word; if we don’t do that, Word will continue to chug away in the background. That probably won’t hurt anything, but ….

That’s all well and good, but what if you change your mind and would like to restore Word 2007 as the default save format? No sweat; just set the value of the DefaultSaveFormat property to docx:

Set objWord = CreateObject(“Word.Application”)

objWord.DefaultSaveFormat = “docx” objWord.Quit

That’s all there is to it.

A couple quick notes here. First, you aren’t limited to using Word 2003 or Word 2007 as the default save formats. In Word 2007, bring up the Save As dialog box and then click on Save as type. Notice all the different file types available to you:

Microsoft Word

We haven’t tried every last one of these, but as far as we know you can set the default save format to any of these file types. Just set the DefaultSaveFormat property to the desired file extension, not including the period. (In other words, RTF, not .RTF.)

In addition, this same script works on earlier versions of Word; it’s not specific to Word 2007. Obviously on Word 2003 you won’t have the same set of file types to choose from, but you can use a script to change the default save format to the file types that are supported by Word 2003.

In closing, we should note that, as part of the TechEd Challenge, we announced that, for one day, we would rename the Script Center after anyone who achieved a perfect score of 140. We haven’t officially scored any of the entries yet, but it’s possible that one or more people have actually achieved a perfect score. If that’s true will we really rename the Script Center after each of these people? Well, for one day at least, yes, we will. Was that a reckless, immature, and irresponsible promise to make? In retrospect, yes, it was.

But don’t worry: Jean will be severely reprimanded for coming up with such an outrageous proposal. You just never know what crazy scheme she’s going to come up with next.

Author

0 comments

Discussion are closed.