
Automation w/WORD 97 - Simple example needed
Quote:
> I need, in VB5 simple code, an example that will open "c:\test.doc", enter the
> text "hi mom" and quit.
> Thanks,
> ian
Hope this helps:
public objWord as word.application
public MomDoc as document
sub WriteHiMom
' GetWord function is below this code
if not GetWord then exit sub
on error resume next
set MomDoc=objWord.Documents.Open("c:\test.doc")
if err then
' Doc not found error handler
exit sub
end if
on error goto 0
objWord.Selection.TypeText "Hi Mom"
objWord.quit
end sub
Public Function GetWord() As Boolean
'
' This method gets an current instance of Word if one is running,
' otherwise it creates an instance
'
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set objWord = CreateObject("Word.Application")
GetWord = True
Exit Function
End If
If Err.Number <> 0 Then
GetWord = False
MsgBox "Microsoft Word Not Found"
Else
GetWord = True
End If
End Function