OK, give this a try.
Rename the docx file to a dotx file. (Website thinks it's invalid.)
Change the paths as required.
Sub CheckListPhraseCreator()
'Creates a Word document using phrase from this worksheet.
Dim WS As Worksheet
Dim Rng As Range
Dim WrdApp As Word.Application
Dim WrdDoc As Word.Document
Dim WrdRng As Word.Range
'Change second number of first set to total number of phrases.
Dim Phrase(1 To 5, 1 To 2) As String
Dim MyPath As String
Dim MyTmplt As String
Dim A As Long
Set WS = ActiveSheet
With WS
'RETIREMENT LOCATION
Phrase(1, 1) = "[LOCATION]"
Phrase(1, 2) = .Range("F3")
'PENSION SCHEME
Phrase(2, 1) = "[PENSION]"
Phrase(2, 2) = .Range("B7")
'CETV
Phrase(3, 1) = "[CTEV]"
Phrase(3, 2) = .Range("D7")
'YEARS TO NRA
Phrase(4, 1) = "[YrsTo]"
Phrase(4, 2) = .Range("H6")
'DEVERE OFFICE
Phrase(5, 1) = "[RETLOC]"
Phrase(5, 2) = .Range("D3")
End With
'Path to Word Template. Change as required.
MyPath = "C:\Users\owner\Mydocuments\"
'Template name. Change as required.
MyTmplt = "CheckList template.dotx"
If Dir(MyPath & MyTmplt) <> "" Then
'Start word and make visible.
Set WrdApp = CreateObject("Word.Application")
WrdApp.Visible = True
Set WrdDoc = WrdApp.Documents.Add(MyPath & MyTmplt, , , True)
With WrdDoc
For A = 1 To 5
Set WrdRng = WrdDoc.Range
With WrdRng.Find
.Text = Phrase(A, 1)
.Replacement.Text = Phrase(A, 2)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
WrdRng.Find.Execute Replace:=wdReplaceAll
Next
'Deletes any prior version.
If Dir(MyPath & WS.Range("b3").Text & ".docx") <> "" Then
Kill MyPath & WS.Range("b3").Text & ".docx"
End If
'Save File using Client name.
.SaveAs2 MyPath & WS.Range("b3").Text, 16
End With
'Closes the Word document
'WrdDoc.Close False
'Closes Word
'WrdApp.Quit
'Releases object
Set WrdDoc = Nothing
Set WrdApp = Nothing
End If
End Sub
This code is kinda fixed, but easy to understand and modify.
I would tend to write a table, like sheet2, to handle a situation like this. (See the second macro.)
Bookmarks