# VBA - Save Word Document Template as New Word Document



## PHayes35 (Dec 13, 2017)

Hey guys, so I have the below code that takes named ranges in Excel and updates them in a word document template I have set up with bookmarks. I'd like to save this word document template as a newly named file, referencing a range on the excel worksheet I'm running the code on. 

Below is my current code, I'm receiving the "object doesn't support this property or method" error on the code in red. Filepath/filename have been renamed for proprietary reasons. 


```
Dim wb As Workbook
    Dim pappWord As Object, docWord As Object
    Dim FlName As String
    Dim xlName As Name
    Dim filePath As String
        
 filePath = "\\CompanyAddress.com\bc1\Files\XXX_Common\XXX\XXXX XX\XXXXXX\Patrick\BET\Term Sheets" 
    
Sheets("Basket Template").Select
    
 FlName = "\\CompanyAddress.com\bc1\Files\XXX_Common\XXX\XXXX XX\XXXXXX\Patrick\BET\Basket Template 1.docm"
 
 
  On Error Resume Next
    Set pappWord = GetObject(, "Word.Application")
       
       
       If Err.Number <> 0 Then
        Set pappWord = CreateObject("Word.Application")
    End If
    Err.Clear
    On Error GoTo 0


   Set docWord = pappWord.Documents.Open(FlName)
   
   Set wb = ActiveWorkbook
   
   Sheets("Basket Template").Select
   
   
    For Each xlName In wb.Names
         'if xlName's name is existing in document then put the value in place of the bookmark
        If docWord.Bookmarks.Exists(xlName.Name) Then
            docWord.Bookmarks(xlName.Name).Range.Text = Range(xlName).Value
        End If
    Next xlName
    
    
      With pappWord
        .Visible = True
        .ActiveWindow.WindowState = 0
        .Activate
[COLOR=#ff0000]        .SaveAs filePath & "\" & Sheets("Basket Template").Range("C2").Value & ".docm"[/COLOR]


        
    End With
```


----------



## NdNoviceHlp (Dec 14, 2017)

```
With docWord
 .SaveAs filePath & "\" & CSTR(Sheets("Basket Template").Range("C2").Value) & ".docm"
End With
```
HTH. Dave


----------



## Macropod (Dec 14, 2017)

I note that you've referred to the Word file you're using a template but it is not, in fact, a Word template. Word templates have extensions like .dot, .dotx or .dotm; yours is a macro-enabled Word document. Furthermore, you'd create a new document from a template using
Set docWord = pappWord.Documents.Add(FlName)
not:
Set docWord = pappWord.Documents.Open(FlName)

As for your SaveAs problem, SaveAs is not a Word application method, its w Word document method. Hence you should have:
docWord.SaveAs2 filePath & "" & Sheets("Basket Template").Range("C2").Value & ".docm", 13 'wdFormatXMLDocumentMacroEnabled
or:
docWord.SaveAs2 filePath & "" & Sheets("Basket Template").Range("C2").Value & ".docx", 12 'wdFormatXMLDocument

There is also no need for:
Sheets("Basket Template").Select
or:
.ActiveWindow.WindowState = 0
.Activate


----------



## PHayes35 (Dec 14, 2017)

Worked perfectly, thank you!!


----------

