Code:
Dim objWrd As Object
Set objWrd = CreateObject("Word.Application")
'Dim objWrd As New Word.Application
Dim objDoc As Word.Document
Dim sln As Word.Selection
'Setting Overtype value to False is very impotant when using selection
objWrd.Options.Overtype = False
Select Case objWrd.Version
Case "9.0", "10.0", "11.0"
Set objDoc = objWrd.Documents.Add(, , 1, True)
Case "8.0"
Set objDoc = objWrd.Documents.Add
Case Else
MsgBox "Unsupported Version of Word.", vbOKOnly + vbExclamation, "Install New Version"
Exit Sub
End Select
Set sln = objWrd.Selection
objDoc.Activate
With sln
.Paragraphs.Alignment = wdAlignParagraphLeft
.Font.Name = "Arial"
.Font.Size = cboFontSize.Text + 2
.BoldRun
.TypeText (Chr(9) & lblDefName.Caption)
.BoldRun
.TypeParagraph
.TypeParagraph
.Font.Size = cboFontSize.Text
'*NEWLINE*
.BoldRun
.TypeText (Chr(9) & " ")
.BoldRun
.TypeText (txtSPN.Text)
.BoldRun
.TypeText (" ")
.BoldRun
Dim i As Integer
For i = 0 To lstCause.ListCount
.TypeText (lstCause.List(i) & " ")
Next i
.TypeParagraph
'*NEWLINE*
.BoldRun
.TypeText (Chr(9) & " ")
.BoldRun
.TypeText (txtDateAct.Text)
.BoldRun
.TypeText (" ")
.BoldRun
.TypeText (cboActType.Text)
.BoldRun
.TypeText (" ")
.BoldRun
.TypeText (txtLOS_lbl.Caption)
.TypeParagraph
.TypeParagraph
'*NEWLINE*
'*NEWLINE*
.BoldRun
.TypeText (" ")
.BoldRun
.TypeParagraph
.TypeText (txtNotes.Text)
.TypeParagraph
If (txtRptDate <> vbNullString) Then
.BoldRun
.TypeText (" ")
.BoldRun
.TypeText (txtRptDate.Text)
.TypeText (" ")
.BoldRun
.TypeText (" ")
.BoldRun
.TypeText (txtRptTime.Text)
End If
.TypeParagraph
.BoldRun
.TypeText (" ")
.BoldRun
.TypeText (lblCSO.Caption)
.ItalicRun
.TypeText (" ")
.ItalicRun
End With
objWrd.Visible = True
objWrd.PrintOut
objWrd.Visible = False
MsgBox "Successfully Printed", vbOKOnly, "Print Successful"
objDoc.Close (False)
objWrd.Quit (False)
Anyone know where the '462' runtime error is occurring in this program?
The users are on different platforms (NT, 2000, XP) with different versions of Microsoft Word.