f



Problem beyond "Hello World": "Hello Word"

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
appl.Visible=true
Set doc=appl.Documents.Add()
appl.Windows(doc.Name").Activate
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
altenatives.

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.


                                                                      Henrik
Land�n

Stockholm




0
kemiinf
10/3/2003 1:34:03 PM
comp.lang.basic.visual 1833 articles. 0 followers. please859 (33) is leader. Post Follow

1 Replies
373 Views

Similar Articles

[PageSpeed] 10

try this substitution:

' appl.Windows(doc.Name).Activate   'replace with:

doc.Activate

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." <kemiinf.ab@stockholm.mail.telia.com> wrote in message
news:fVefb.27183$mU6.67919@newsb.telia.net...
> 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
> appl.Visible=true
> Set doc=appl.Documents.Add()
> appl.Windows(doc.Name").Activate
> 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
> altenatives.
>
> 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.
>
>
>                                                                       Henrik
> Land�n
>
> Stockholm
>
>
>
>


0
Steve
10/4/2003 3:20:12 AM
Reply: