Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two pieces of bad news to give here.</p> <p>1) A document has to have a template. You cannot remove it, only change it to something else.</p> <p>2) Changing a template does nothing anyway. See <a href="http://www.shaunakelly.com/word/templates/attachtemplate.html" rel="noreferrer" title="Changing a Word template">this page</a>.</p> <p>I am wonder if the problem with the Open method is that you are trying to open ".doc" extension files, not the modern ".docx" extension files. The VBA subroutine you linked to only does ".doc" files. This VBA code does both:</p> <pre><code>Function StringEndsWith( _ ByVal strValue As String, _ CheckFor As String) As Boolean Dim sCompare As String Dim lLen As Long lLen = Len(CheckFor) If lLen &gt; Len(strValue) Then Exit Function sCompare = Right(strValue, lLen) StringEndsWith = StrComp(sCompare, CheckFor, vbTextCompare) = 0 End Function Sub ChangeTemplates() Dim strDocPath As String Dim strTemplateB As String Dim strCurDoc As String Dim docCurDoc As Document ' set document folder path and template strings strDocPath = "C:\tmp\" ' get first doc - only time need to provide file spec strCurDoc = Dir(strDocPath &amp; "*.doc*") ' ready to loop (for as long as file found) Do While strCurDoc &lt;&gt; "" If (StringEndsWith(strCurDoc, ".doc") Or StringEndsWith(strCurDoc, ".docx")) Then ' open file Set docCurDoc = Documents.Open(FileName:=strDocPath &amp; strCurDoc) ' change the template back to Normal docCurDoc.AttachedTemplate = "" ' save and close docCurDoc.Close wdSaveChanges End If ' get next file name strCurDoc = Dir Loop MsgBox "Finished" End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload