Private Sub InsertToTemplate3(Columns() As String, ByRef Year As Integer)
'inserts the preformayed columns text into the template then saves it
Dim sPath As String
Dim MSWord As Word.Application
Dim TemplateDOC As Document
Dim myRange As Word.Range
Dim lM As Long
Dim lD As Long
Dim sFind As String
staBar.Panels(1).Text = "Initalizing MSWord"
sPath = App.Path & "\Template\TableTemplate12g.dot"
Set MSWord = New Word.Application
With MSWord
' .Visible = True
'Load the template
Set TemplateDOC = .Documents.Open(sPath)
.Selection.WholeStory
.Selection.Copy
'create a ne document from the template
.Documents.Add DocumentType:=wdNewBlankDocument
.Selection.PasteAndFormat (wdPasteDefault)
Set myRange = ActiveDocument.Content
'notify the user
staBar.Panels(1).Text = "Creating Word Document"
Screen.MousePointer = vbDefault
ProgressBarInitalize 365
'Set the Name of Location
sFind = "Name of Location"
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=m_sLocName, _
Replace:=wdReplaceAll
'Set the Year
sFind = "Year"
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=CStr(Year), _
Replace:=wdReplaceAll
For lM = 1 To 12
For lD = 1 To 31
ProgressBarDecrement
'add the Day Numeral
sFind = "Dm" & CStr(lM) & "d" & CStr(lD)
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=Columns(lM, 0, lD), _
Replace:=wdReplaceAll
'add the Day Name
sFind = "Wm" & CStr(lM) & "d" & CStr(lD)
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=Columns(lM, 1, lD), _
Replace:=wdReplaceAll
'add the Moon Phase
sFind = "Sm" & CStr(lM) & "d" & CStr(lD)
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=Columns(lM, 2, lD), _
Replace:=wdReplaceAll
'add the Time column
sFind = "Tm" & CStr(lM) & "d" & CStr(lD)
myRange.Find.Execute FindText:=sFind, _
MatchCase:=True, _
MatchWholeWord:=True, _
ReplaceWith:=Columns(lM, 3, lD), _
Replace:=wdReplaceAll
Next
Next
.Visible = True
End With
'Clear the progress bar
ProgressBarClear
staBar.Panels(1).Text = "Processing Complete"
staBar.Panels(2).Text = "Use MS Word to save the file."
'kill the MS Word objects
TemplateDOC.Close
Set MSWord = Nothing
Set TemplateDOC = Nothing
Set myRange = Nothing
End Sub