View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
AP[_6_] AP[_6_] is offline
external usenet poster
 
Posts: 5
Default Write to MS Word

On Feb 21, 12:10*am, Mike H wrote:
Hi,

You weren't seeing an error because your error handler was doing what you
told it to do and handling the error

Sub Write_to_Word()
Dim objApp As Object
On Error Resume Next
Set objApp = GetObject(, "Word.Application")

If Err.Number < 0 Then
* * On Error GoTo ErrHandler
* * Set objApp = CreateObject("Word.Application")
Else
* * 'Bound to instance, activate error handling
* * On Error GoTo ErrHandler
End If
With objApp
* * * * .Visible = True
* * * * .Documents.Add
* * * * .Selection.Font.Name = "Arial"
* * * * .Selection.TypeText "Hello"
* * * * .Selection.TypeParagraph
* * * * .Selection.TypeText Text:="Hello 2"
* * End With
Set objApp = Nothing
Exit Sub
ErrHandler:
'Release the object and resume normal error handling
Set objApp = Nothing
On Error GoTo 0 'Display standard run time error message box
End Sub
--
Mike



Thanks very much Mike - it works beautifully !!!

AP