Dim m_oWordApp
Dim m_oWordDoc
Set m_oWordApp= Server.CreateObject("Word.Application")
Set m_oWordDoc= m_oWordApp.Documents.Add(Server.MapPath("mytemplate.dot"))
m_oWordApp.Activate
m_oWordApp.System.Applications.Options.Pagination = True
Sub ReportHeader()
Dim oParentTable As Word.Table
Dim oCell As Word.Cell
Set oParentTable = m_oWordApp.Selection.Tables.Add(m_oWordApp.Selection.Range, 1, 2)
oParentTable.Id = "tblReportHeader"
oParentTable.Select
oParentTable.AllowAutoFit = True
oParentTable.AutoFitBehavior wdAutoFitContent
oParentTable.PreferredWidth = InchesToPoints(6.5)
oParentTable.Borders.OutsideLineStyle = wdLineStyleNone
oParentTable.Borders.InsideLineStyle = wdLineStyleNone
Set oCell = oParentTable.Cell(1, 1)
oCell.Select
m_oWordApp.Selection.Font.Name = "Times New Roman"
m_oWordApp.Selection.Font.Size = 34
m_oWordApp.Selection.Font.Color = wdColorDarkBlue
m_oWordApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
m_oWordApp.Selection.Font.Bold = True
m_oWordApp.Selection.TypeText "Report Title" & vbCrLf
Set oCell = oParentTable.Cell(1, 2)
oCell.Select
oCell.Column.Select
Dim strAddress As String
strAddress = "blah blah blah"
m_oWordApp.Selection.Font.Name = "Times New Roman"
m_oWordApp.Selection.Font.Size = 8
m_oWordApp.Selection.Font.Color = wdColorBlack
m_oWordApp.Selection.Font.Bold = True
m_oWordApp.Selection.TypeText strAddress & vbCrLf
oParentTable.PreferredWidth = InchesToPoints(6.5)
Set oCell = Nothing
Set oParentTable = Nothing
End Sub
Private Sub EndSection()
m_oWordApp.Selection.TypeText vbCrLf
m_oWordApp.Selection.GoToNext wdGoToLine
End Sub
Private Sub NextLine()
m_oWordApp.Selection.GoToNext wdGoToLine
End Sub