Easy way to convert templates to documents?

P

Peter Bako

I have a client where about a year ago a user started a document and saved
it as a .dot file. The problem is that she kept the file out in an open
area that everyone else can get to and people started to use it as a
template - but not in the Word use of the term. Instead they double click
on it, modify it and then do a File/Save As on it without changing the file
type to a .doc file. Since then this has multiplied into hundreds (if not
thousands) of .dot files across the server being used as if they were real
Word documents.

This occasionally causes weird issues with Word, so I've recommended that
they convert all these into .doc files. Problem is the only way I know of
to do this, is to drag each .dot file into their My Templates folder, start
Word and then create a new document based on this "template". Once the
document comes up, do an immediate Save As to a doc file, then delete the
original .dot and replace it. As you can imagine this is painful and a few
of my users are having problems even getting this to work.

So, is there any kind of an easy way to convert a large number of .dot files
to .doc files? Or at least an easier way to convert a single .dot to a .doc
that I can have the users do? I've tried to just double click on the .dot
file (which opens up in template edit mode not as a new doc) and then do a
Save As do a .doc file, but you get an error saying you cannot save a
template as a doc format!

About 90% of the users are running Office V.x but a few are running 2004.

Thanks,
Peter
 
C

CyberTaz

Hi Peter-

Although this can probably be done with a script I can't tell you how to go
about automating the process. However, if you go to Finder> Preferences>
Advanced & check the option for Show all file extensions, you can edit the
filenames in the Finder to .doc to change the file type. Another option
would be to work through the file's Get Info panel to do the same thing.

HTH |:>)


I have a client where about a year ago a user started a document and saved
it as a .dot file. The problem is that she kept the file out in an open
area that everyone else can get to and people started to use it as a
template - but not in the Word use of the term. Instead they double click
on it, modify it and then do a File/Save As on it without changing the file
type to a .doc file. Since then this has multiplied into hundreds (if not
thousands) of .dot files across the server being used as if they were real
Word documents.

This occasionally causes weird issues with Word, so I've recommended that
they convert all these into .doc files. Problem is the only way I know of
to do this, is to drag each .dot file into their My Templates folder, start
Word and then create a new document based on this "template". Once the
document comes up, do an immediate Save As to a doc file, then delete the
original .dot and replace it. As you can imagine this is painful and a few
of my users are having problems even getting this to work.

So, is there any kind of an easy way to convert a large number of .dot files
to .doc files? Or at least an easier way to convert a single .dot to a .doc
that I can have the users do? I've tried to just double click on the .dot
file (which opens up in template edit mode not as a new doc) and then do a
Save As do a .doc file, but you get an error saying you cannot save a
template as a doc format!

About 90% of the users are running Office V.x but a few are running 2004.

Thanks,
Peter

-- (e-mail address removed)
 
P

Paul Berkowitz

It would not be a good idea AT ALL to change the extension of a .dot
template to ".doc". Since the structure of the file is a .dot template. you
would be screwing things up so badly that probably nothing much would ever
work right again. This is a really,. really bad faux pas you've just
recommended, CyberTaz, as I'm sure you'll agree if you think about it for a
minute.

There probably is a safe way of automating the process of creating documents
from the templates, then deleting the templates, by script, but the only
safe way of doing it manually is the way Peter has been doing it: move all
the .dot files to My Templates, open them all from the Project Gallery, and
"Save As" the opened "Document1", etc. with the original document
(ex-template) name as Word Document with .doc extension. The tedious part is
copying the name from the Finder to paste into the Save As dialog every
time. There's no way around that.

I can check out a script to see if it will work on a selection of .cot files
without having to move them anywhere. Back soon...

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
P

Peter Bako

Thanks Paul. I knew that just renaming the file to a different extension is
a bad idea, heck that doesn't even work on a PC much less a Mac. There are
distinct file format differences between a plain .doc file and a .dot file.

I'm still trying to learn AppleScript, so I am nowhere near to writing a
script of this caliber, but if you could find one that I can use as a basis,
that would be great!!!

Peter
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Peter:

He WON'T be back "soon" :)

We just discovered a revolting bug that makes this operation very difficult.
Paul will be right with you ... :)

In the meantime, if you had a copy of WinWord handy, this is trivial in
WinWord. When you double-click on a .dot in WinWord, it creates a document
from the template. You can then save that with the correct name.

If you do have WinWord handy, get back to me: I can give you some bits of
VBA that will do this on Windows.

Otherwise, you will need to wait for Paul's script, which presumably will
have the ability to get all the .dots in a folder one by one, convert them,
and delete the original.

Just as an aside, Mac Word's handling of templates is "wrong" for those of
us accustomed to the PC way of doing things. On the PC, if you double-click
a .dot, regardless of where it is, you get a DOCUMENT created from and
attached to the template. On the Mac, you OPEN the template.

I screamed about this in the beta, because I understood that it would cause
mayhem in a corporate setting. But others new best... {sigh} :)

Thanks Paul. I knew that just renaming the file to a different extension is
a bad idea, heck that doesn't even work on a PC much less a Mac. There are
distinct file format differences between a plain .doc file and a .dot file.

I'm still trying to learn AppleScript, so I am nowhere near to writing a
script of this caliber, but if you could find one that I can use as a basis,
that would be great!!!

Peter

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
P

Paul Berkowitz

Peter,

John's right. There's a bug in AppleScript that doesn't allow it to be done
the way it should,

It can still be done the old pre-2004 way using 'do Visual Basic', though,
thanks to a macro John produced. The AppleScript wrapping will still allow a
bunch of selected .dot files to be dropped on an applet - or a command to
find every .dot file in a folder and work on those. Which of those methods
is better for your users?

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
P

Paul Berkowitz

It can still be done the old pre-2004 way using 'do Visual Basic', though,
thanks to a macro John produced. The AppleScript wrapping will still allow a
bunch of selected .dot files to be dropped on an applet - or a command to
find every .dot file in a folder and work on those. Which of those methods
is better for your users?

OK, this version will do it either way: copy and paste it into Script
Editor, and save it as an Application (flip the File Format popup in the
Save dialog to "application") called "Template to Doc.app" or something like
that. It will be simplest to drag it to your Dock and run it from there. You
can either command-click to select all the .dot files or extension-less
template files in a folder, then drag them onto the applet in the Dock, or
else just click the applet in the Dock (or double-click it where it lives)
and choose the folder whose .dot files or templates you wish to convert. If
you make a mistake by choosing a file that should have been left as .dot,
you'll find it in the Trash.

----------------------Template to Doc.app--------------------------

on run

set theFolder to choose folder with prompt "Choose the folder whose .dot
Word template files you wish to convert to .doc documents:"
tell application "Finder"
try
set theFiles to (every file of theFolder whose name extension is
"dot" or file type is "W8TN") as alias list
on error -- Finder bug whenthere's only one file
set theFiles to (every file of theFolder whose name extension is
"dot" or file type is "W8TN") as alias as list
end try
end tell
open theFiles

end run


on open theFiles

repeat with i from 1 to (count theFiles)
set theFile to item i of theFiles
set fileInfo to info for theFile
if name extension of fileInfo is "dot" or file type of fileInfo is
"W8TN" then
my ChangeToDoc(theFile)
end if
end repeat

end open


to ChangeToDoc(theFile)

set dotFilePath to theFile as Unicode text
set AppleScript's text item delimiters to {":"}
set folderPath to (text items 1 thru -2 of dotFilePath as Unicode text)
& ":"
set dotName to text item -1 of dotFilePath
if dotName ends with ".dot" then
set docName to text 1 thru -5 of dotName & ".doc"
else
set docName to dotName & ".doc"
end if
set AppleScript's text item delimiters to {""}

tell application "Microsoft Word"
try -- in case of error re "not enough memory to display picture",
etc., ignore the error
do Visual Basic "Documents.Add Template:= \"" & dotFilePath &
"\""
end try
save active document in (folderPath & docName)
close document docName saving yes
end tell

tell application "Finder" to delete theFile
end ChangeToDoc


----------------------------------------------------


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Paul:

That¹s a nice bit of code :) Well done!

Cheers


OK, this version will do it either way: copy and paste it into Script Editor,
and save it as an Application (flip the File Format popup in the Save dialog
to "application") called "Template to Doc.app" or something like that. It will
be simplest to drag it to your Dock and run it from there. You can either
command-click to select all the .dot files or extension-less template files in
a folder, then drag them onto the applet in the Dock, or else just click the
applet in the Dock (or double-click it where it lives) and choose the folder
whose .dot files or templates you wish to convert. If you make a mistake by
choosing a file that should have been left as .dot, you'll find it in the
Trash.

----------------------Template to Doc.app--------------------------

on run

set theFolder to choose folder with prompt "Choose the folder whose .dot
Word template files you wish to convert to .doc documents:"
tell application "Finder"
try
set theFiles to (every file of theFolder whose name extension is
"dot" or file type is "W8TN") as alias list
on error -- Finder bug whenthere's only one file
set theFiles to (every file of theFolder whose name extension is
"dot" or file type is "W8TN") as alias as list
end try
end tell
open theFiles

end run


on open theFiles

repeat with i from 1 to (count theFiles)
set theFile to item i of theFiles
set fileInfo to info for theFile
if name extension of fileInfo is "dot" or file type of fileInfo is
"W8TN" then
my ChangeToDoc(theFile)
end if
end repeat

end open


to ChangeToDoc(theFile)

set dotFilePath to theFile as Unicode text
set AppleScript's text item delimiters to {":"}
set folderPath to (text items 1 thru -2 of dotFilePath as Unicode text) &
":"
set dotName to text item -1 of dotFilePath
if dotName ends with ".dot" then
set docName to text 1 thru -5 of dotName & ".doc"
else
set docName to dotName & ".doc"
end if
set AppleScript's text item delimiters to {""}

tell application "Microsoft Word"
try -- in case of error re "not enough memory to display picture",
etc., ignore the error
do Visual Basic "Documents.Add Template:= \"" & dotFilePath & "\""
end try
save active document in (folderPath & docName)
close document docName saving yes
end tell

tell application "Finder" to delete theFile
end ChangeToDoc


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
P

Peter Bako

I would much prefer for the users to drop individual (or a small group) of
templates onto the app rather than a utility that finds all of them and
converts on the fly. For one most of these users are not very technical, so
if they mess this up I would rather restore a few files than a whole mess,
plus very few of the files actually have extensions on them...

Peter
 
P

Peter Bako

Re: Easy way to convert templates to documents?Cool! I'll try this and see what it does! Thanks for all the help....
It can still be done the old pre-2004 way using 'do Visual Basic', though,
thanks to a macro John produced. The AppleScript wrapping will still allow a
bunch of selected .dot files to be dropped on an applet - or a command to
find every .dot file in a folder and work on those. Which of those methods
is better for your users?

OK, this version will do it either way: copy and paste it into Script Editor, and save it as an Application (flip the File Format popup in the Save dialog to "application") called "Template to Doc.app" or something like that. It will be simplest to drag it to your Dock and run it from there. You can either command-click to select all the .dot files or extension-less template files in a folder, then drag them onto the applet in the Dock, or else just click the applet in the Dock (or double-click it where it lives) and choose the folder whose .dot files or templates you wish to convert. If you make a mistake by choosing a file that should have been left as .dot, you'll find it in the Trash.

----------------------Template to Doc.app--------------------------

on run

set theFolder to choose folder with prompt "Choose the folder whose .dot Word template files you wish to convert to .doc documents:"
tell application "Finder"
try
set theFiles to (every file of theFolder whose name extension is "dot" or file type is "W8TN") as alias list
on error -- Finder bug whenthere's only one file
set theFiles to (every file of theFolder whose name extension is "dot" or file type is "W8TN") as alias as list
end try
end tell
open theFiles

end run


on open theFiles

repeat with i from 1 to (count theFiles)
set theFile to item i of theFiles
set fileInfo to info for theFile
if name extension of fileInfo is "dot" or file type of fileInfo is "W8TN" then
my ChangeToDoc(theFile)
end if
end repeat

end open


to ChangeToDoc(theFile)

set dotFilePath to theFile as Unicode text
set AppleScript's text item delimiters to {":"}
set folderPath to (text items 1 thru -2 of dotFilePath as Unicode text) & ":"
set dotName to text item -1 of dotFilePath
if dotName ends with ".dot" then
set docName to text 1 thru -5 of dotName & ".doc"
else
set docName to dotName & ".doc"
end if
set AppleScript's text item delimiters to {""}

tell application "Microsoft Word"
try -- in case of error re "not enough memory to display picture", etc., ignore the error
do Visual Basic "Documents.Add Template:= \"" & dotFilePath & "\""
end try
save active document in (folderPath & docName)
close document docName saving yes
end tell

tell application "Finder" to delete theFile
end ChangeToDoc


----------------------------------------------------


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be ignored.

PLEASE always state which version of Microsoft Office you are using - **2004**, X or 2001. It's often impossible to answer your questions otherwise.
 
P

Peter Bako

I only have Office 2004 on my laptop here, but I will try it on a V.x
version tomorrow. In the meanwhile I figured let¹s try it with my system.
I get the following error: ³active document doesn't understand the save
message² from Word ­ what is the difference between the two versions that
causes it to fail on a 2004 version?

Thanks!
Peter
 
P

Paul Berkowitz

Nothing. I wrote it and ran it in 2004. There is an alternative 'save'
variety that would work only in 2004, but I didn't use it. There might be a
good reason to include the save and close lines in do Visual basic as well
if you're expecting to use this in Word X. (Did you ever say so?)

As to why you're getting that error? There's probably some error I didn't
anticipate which is preventing a new Document being created. (Or did you
find one there - Document 2 or similar which looked like the template.) The
error I was trying to avoid was just one I hit myself - which made the
document but threw an error due to "not enough memory to display pictures".
If you remove the 'try' and 'end try' lines, you should discover what the
error in fact really is (you'll see it pop up in Word). Let me know what it
says, and we'll see if we can work around it or fix it.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.



From: Peter Bako <[email protected]>
Newsgroups: microsoft.public.mac.office.word
Date: Sun, 10 Apr 2005 22:16:13 -0700
Subject: Re: Easy way to convert templates to documents?

I only have Office 2004 on my laptop here, but I will try it on a V.x
version tomorrow. In the meanwhile I figured let¹s try it with my system.
I get the following error: ³active document doesn't understand the save
message² from Word ­ what is the difference between the two versions that
causes it to fail on a 2004 version?

Thanks!
Peter
 
M

mmmmark

In PC versions of Word, templates do indeed behave differently. For
example, if a .dot is created (and it can be saved anywhere by the way) and
double-clicked, it will open as "Document x". However, if opened from the
File menu, it will open as "Filename.dot".

The first way, you can Save as anything. The second way, you have to Save
As and change the file type to .doc when you save to save as something else.
Incidentally, you can happily change a PC Word file from .doc to .dot and it
will behave as expected--at least on the PC side (never taken one over to
Mac for testing).

The behavior in the first paragraph has confused many people at my company
as we use .dot files extensively for various forms. The confusion comes
from some people being "openers" while others--myself included--being "find
and clickers."

-Mark
 
P

Peter Bako

Well took a bit of tweaking but here is what I came up with. These changes
work on both Word 2004 and V.x versions. It required the changing of the
Visual Basic lines in the ChangeToDoc routine to this:

tell application "Microsoft Word"
do Visual Basic "Documents.Add Template:= \"" & dotFilePath & "\""
do Visual Basic "activeDocument.SaveAS Filename:=\"" & folderPath &
docName & "\""
do Visual Basic "activeDocument.close"
end tell

This way it all works! Thanks for all the help!!!

Peter
 
M

Matt Centurión [MSFT]

Not to be a party-pooper or anything but in case all you want to retain from
the template is the text and styles this will work fine. However if the
Template contains Customized Toolbars/Keyboard, Macros, or AutoText then the
document will expect to have the template available to pull these from. If
you want to distribute the docs without the templates then don¹t expect the
Customizations/Macros/Autotext originally in the template to work.

To get around that, you¹d have to use the Organizer (through VB even) to
copy those items over as well. However, it has been noted that our customers
would like an easier way to save templates as documents.


Matt
MacWord Testing
MacBU - Microsoft


Well took a bit of tweaking but here is what I came up with. These changes
work on both Word 2004 and V.x versions. It required the changing of the
Visual Basic lines in the ChangeToDoc routine to this:

tell application "Microsoft Word"
do Visual Basic "Documents.Add Template:= \"" & dotFilePath & "\""
do Visual Basic "activeDocument.SaveAS Filename:=\"" & folderPath &
docName & "\""
do Visual Basic "activeDocument.close"
end tell

This way it all works! Thanks for all the help!!!

Peter









--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this e-mail address. It is for
newsgroup purposes only.

Find out everything about Microsoft Mac Newsgroups at:
http://www.microsoft.com/mac/community/community.aspx?pid=newsgroups
Check out product updates and news & info at:
http://www.microsoft.com/mac
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Matt:

³double-click² works rather well on the PC :)

I seem to remember having a few rounds of the kitchen with your good self on
this very topic a few years ago, and you wouldn¹t give in :)

But then, I am not so unkind as to say things like ³I told you so...² That
would be ungentlemanly, now wouldn¹t it? <G, d, & r r r r r....>

Cheers

Not to be a party-pooper or anything but in case all you want to retain from
the template is the text and styles this will work fine. However if the
Template contains Customized Toolbars/Keyboard, Macros, or AutoText then the
document will expect to have the template available to pull these from. If you
want to distribute the docs without the templates then don¹t expect the
Customizations/Macros/Autotext originally in the template to work.

To get around that, you¹d have to use the Organizer (through VB even) to copy
those items over as well. However, it has been noted that our customers would
like an easier way to save templates as documents.


Matt
MacWord Testing
MacBU - Microsoft












--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this e-mail address. It is for
newsgroup purposes only.

Find out everything about Microsoft Mac Newsgroups at:
http://www.microsoft.com/mac/community/community.aspx? pid=newsgroups
<http://www.microsoft.com/mac/community/community.aspx?pid=newsgroups>
Check out product updates and news & info at:
http://www.microsoft.com/mac


--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top