try this substitution:
' appl.Windows(doc.Name).Activate 'replace with:
I think the document name may not always get set right away, since Word has to
decide if it should be Document1, Document2, etc. The doc.Activate version is
more to the point anyway.
"kemiinf." <firstname.lastname@example.org> wrote in message
> Hi everybody
> I�m still working on a program that types to a Word document. My program
> opens a Word document and shall work if Word is already running or not.
> The user are able to do anything with the opened document and application:
> close them or not.
> I have extracted the problematic lines from my code. This simple program
> have just a form with a command button:
> Private sub Command1_Click
> Dim appl As Word.Application
> Dim doc As Word.Document
> On Error Resume Next
> Set appl=GetObject(,"Word.Application")
> If Err.Number<>0 Then
> Set appl=CreateObject("Word.Application")
> End If
> Set doc=appl.Documents.Add()
> Selection.TypeText "Hello Word"
> Set doc=Nothing
> Set appl=Nothing
> End Sub
> The purpose is that the user shall repeatedly use the comman button and
> create a new document. The user shall also be able to close both the
> application and document "manually". The user have therefore different
> 1 Let both the application and created document be open. Then my program
> works and creates a new document and types "Hello Word".
> 2 Close the opened document and let the application be open. Then my program
> works and creates a new document and types "Hello Word"
> 3 The user both closes the document and application. Then the program opens
> the application and a new document the next time the user clicks the command
> button. but nothing is typed to the document.
> How shall I correct this so that the text is typed to the document.
> Hope someone understands my question and have an answer.