Sub Button1_Click()
Application.ScreenUpdating = False
'Note: A reference to the Word library must be set, via Tools|References
Dim wdApp As New Word.Application, WdDoc As Word.document, StrNm As String
Const BkMkNm As String = "MyBookmark"
StrNm = "C:\Users\" & Environ("UserName") & "\Documents\MyTemplate.dotx"
If Dir(StrNm) <> "" Then
wdApp.Visible = False
With wdApp
Set WdDoc = Documents.Add(Template:=StrNm, Visible:=False)
With WdDoc
If .Bookmarks.Exists(BkMkNm) Then
.Bookmarks(BkMkNm).Range.Text = ActiveSheet.Range("B5").Value
.SaveAs2 Filename:=Split(StrNm, ".dotx")(0) & ActiveSheet.Range("B5").Value & ".docx", _
FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
.Close True
Else
MsgBox "Bookmark: " & BkMkNm & " not found in:" & vbCr & StrNm
End If
End With
.Quit
End With
Else
MsgBox "File: " & StrNm & " not found."
End If
Set WdDoc = Nothing: Set wdApp = Nothing
Application.ScreenUpdating = True
End Sub