Code:
Private Sub printMsg()
Dim objWrd As Object
Dim objDoc As Object
Dim sln As Object
Set objWrd = CreateObject("Word.Application")
'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 = 0
.Font.Name = "Arial"
.Font.Size = cboFontSize.Text
.TypeParagraph
.BoldRun
.TypeText ("<info>")
.BoldRun
.TypeText (label1.Caption)
.ItalicRun
.TypeText ("<moreinfo>")
.ItalicRun
End With
objWrd.Visible = True
objWrd.PrintOut
Set sln = Nothing
objDoc.Close (False)
Set objDoc = Nothing
MsgBox "Message Successfully Printed", vbOKOnly, "Print Successful"
End Sub
For some reason I am having issues with a piece of code which is very common to this. I am also having problems with a Spell Checker using Word as well, but I will post another thread for that.
This one throws a '462' error which means that an instance or a method of Word is not being called correctly or something, but I can not find it in the program.
I don't close the Word Application after use because the user may be using the application for other things. Would this be the problem and how would I get around it. Thanks in advanced.