Bulk conversion of .dot to .doc

M

Melissa

Hi there,

I need to change about 100 word templates to documents. Is there a quick
way to do this in bulk, rather than renaming each one? I am doing this
because I want these documents to be firm precedents and I need them to be
based on one of our templates (usinng templates and add-ins).

Thanks
 
J

Jean-Guy Marcil

Melissa was telling us:
Melissa nous racontait que :
Hi there,

I need to change about 100 word templates to documents. Is there a
quick way to do this in bulk, rather than renaming each one? I am
doing this because I want these documents to be firm precedents and I
need them to be based on one of our templates (usinng templates and
add-ins).

Try something liike this:

'_______________________________________
Option Explicit

'_______________________________________
Public Sub BatchSaveAllAsDoc()

Dim myFile As String
Dim PathToUse As String
Dim PathToSave As String
Dim myDoc As Document

PathToUse = "C:\Test\"
PathToSave = PathToUse & "Doc\"

'Create directory if it does not exist
If Dir(PathToSave, vbDirectory) = "" Then
MkDir PathToSave
End If

'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.dot")

While myFile <> ""
'Open template
Set myDoc = Documents.Open(PathToUse & myFile)
With myDoc
.SaveAs PathToSave & Left(myFile, Len(myFile) - 3) & "doc"
.Close
End With
'Next file in folder
myFile = Dir$()
Wend

End Sub
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Melissa

Thanks very much. That worked a treat. However, when I open one for the
documents and go to templates and add-ins to attach my template, the box is
greyed out, as if it were still a template. Do you know of a work-around for
this?
 
J

Jean-Guy Marcil

Melissa was telling us:
Melissa nous racontait que :
Thanks very much. That worked a treat. However, when I open one for
the documents and go to templates and add-ins to attach my template,
the box is greyed out, as if it were still a template. Do you know
of a work-around for this?


Yes, sorry about this; I should not have used "Documents.Open" with
Templates...

Replace
Set myDoc = Documents.Open(PathToUse & myFile)
by
Set myDoc = Documents.Add(PathToUse & myFile)

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Melissa

Thank you very much. That worked perfectly. If you have the time, can you
please explain why Documents.Add created the doc without the templates and
add-ins greyed out, but Documents.Open did not, or direct me to a site that
might explain it.
 
J

Jonathan West

Melissa said:
Thank you very much. That worked perfectly. If you have the time, can
you
please explain why Documents.Add created the doc without the templates and
add-ins greyed out, but Documents.Open did not, or direct me to a site
that
might explain it.

It is a idiosyncrasy of Word. You can never "Save As" a template as a
different file type. But you can create a new document based on a template,
and save that new document. The Documents.Add method is the VBA equivalent
of creating a new document based on a template.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
R

Rob Benz

Can you describe how to make this work in reverse, ie, bulk convert all .docx
in a folder to .dotx???
Thanks
 
G

Graham Mayor

The following will save all docx documents in a folder as dotx templates
into the same folder. I have not included error trapping for e.g. protected
files.

Sub SaveAllAsDOTX()
Dim strFilename As String
Dim strDocName As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFilename = Dir$(strPath & "*.docx")

While Len(strFilename) <> 0
Set oDoc = Documents.Open(strPath & strFilename)

strDocName = ActiveDocument.FullName
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".dotx"
oDoc.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatXMLTemplate
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFilename = Dir$()
Wend
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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