Sub buildWordDoc()
' header value
'********************************************************************************
header = "My Document Header"
'Builds word application and document
'********************************************************************************
Set setupWordApp = CreateObject("Word.Application")
Set setupReport = setupWordApp.Documents.Add
setupReport.Select
setupReport.PageSetup.LeftMargin = 60
setupReport.PageSetup.RightMargin = 60
setupWordApp.Visible = True
'Sets Font information and inserts header
With setupWordApp.Selection
.Font.Size = 12
.Font.Name = "Elephant"
.Font.Color = wdColorDarkBlue
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeText header
End With
setupWordApp.Selection.TypeParagraph
setupWordApp.Selection.TypeParagraph
With setupWordApp.Selection
.Font.Bold = True
.Font.Name = "Tahoma"
.Font.Color = wdColorBlack
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.TypeText "User Information:"
End With
setupWordApp.Selection.TypeParagraph
'Build MSWord Table "User Information"
'********************************************************************
setupWordApp.Selection.Tables.Add Selection.Range, 2, 3, wdWord9TableBehavior, wdAutoFitFixed
setupWordApp.Selection.MoveDown wdScreen, 1
setupWordApp.Selection.TypeParagraph
With setupWordApp.Selection
.Font.Bold = True
.Font.Name = "Tahoma"
.Font.Color = wdColorBlack
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.TypeText "Computer Information:"
End With
setupWordApp.Selection.TypeParagraph
'Build MSWord Table "PC Information"
'*********************************************************************
setupWordApp.Selection.Tables.Add Selection.Range, 4, 3, wdWord9TableBehavior, wdAutoFitFixed 'builds a table
setupWordApp.Selection.MoveDown wdScreen, 1 'moves to end of document (pg down)
[COLOR=red]<<< This is a note to indicate where the code breaks >>> [/color]
setupWordApp.Selection.Tables(1).Select
setupWordApp.Selection.Collapse wdCollapseStart
With setupWordApp.Selection
.Font.Name = "Garamond"
.TypeText "User ID: " & UserID
.MoveRight
.Font.Name = "Garamond"
.TypeText "Name: " & userFirstName & " " & userLastName
.MoveRight
.Font.Name = "Garamond"
.TypeText "Setup Tech: " & technician
.MoveDown
.MoveLeft
.MoveLeft
.Font.Name = "Garamond"
.TypeText "Date Assigned: "
.MoveRight
.Font.Name = "Garamond"
.TypeText "Date Due: "
.MoveRight
.Font.Name = "Garamond"
.TypeText "Location: " & Location
End With
' setupReport.Tables(2).Select 'selects Tables(n) in active document
' Selection.Collapse wdCollapseStart 'set insertion point to first block
' With Selection
' .Font.Name = "Garamond"
' '.Font.AllCaps = True
' .TypeText "Manufacturer: " & manufacturer
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "Model: " & Model
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "Service Tag: " & ServiceTag
' .MoveDown
' .MoveLeft
' .MoveLeft
' .Font.Name = "Garamond"
' .TypeText "Name: " & computerName
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "Image: " & imageUsed
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "O/S: " & oSys
' .MoveDown
' .MoveLeft
' .MoveLeft
' .Font.Name = "Garamond"
' .TypeText "CPU: " & processor
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "Memory: " & RAM
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "Style: " & fFactor
' .MoveDown
' .MoveLeft
' .MoveLeft
' .Font.Name = "Garamond"
' .TypeText "Asset Tag: " & assTag
' .MoveRight
' .Font.Name = "Garamond"
' .TypeText "Upgrade Type: " & upgradeType
'
' End With
' setupReport.Select
'
'
'
' 'Selection.MoveDown wdScreen, 1
' 'Selection.Range.MoveEnd
'
' 'num = setupReport.Sections.Count
' 'setupReport.Sections(num).Range.Select
' Selection.Collapse wdCollapseEnd
' Selection.TypeParagraph
' 'Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
' Selection.Font.Size = 12
' Selection.Font.Name = "Garamond"
' Selection.TypeText " Set Computer Name To " & computerName
'
'
' Selection.TypeText ("end")
'
' 'Saves Report as temporary document for testing and closes the Word Application
' '****************************************************************************
setupReport.SaveAs ("c:\Test.doc")
setupWordApp.Quit
Set setupReport = Nothing
Set setupWordApp = Nothing
'Starts Word and opens the test document
'****************************************************************************
'Shell ("c:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE c:\test.doc")