Using Automation with Microsoft Word

We are taking text from a Rich Textbox control on a VB form and putting it into a new instance of Microsoft Word. We want to be able to edit the text in the Word document, close the document and put the edited text back into the Rich Textbox control. This is the code sample:

Private Sub cmdShowWord_Click() Dim oDoc As Word.Document

If MSWordOpen() Then ' Add a New Document Set oDoc = goWord.Documents.Add ' Add Information to the Document oDoc.Range.Text = txtSentence

At this point, we want Word to "pause" so that the user can edit the text that we placed into oDoc.Range.Text, disable the Save button since we don't want to save the file to a directory on the network, close the document and finally return the text back into the Rich Text Box control on our VB form.

' Get Sentence Back From Word Document txtSentence.Text = oDoc.Range.Text

End IfEnd Sub

We would appreciate any code that would help achieve our objective. Thank you.

Comments

: We are taking text from a Rich Textbox control on a VB form and putting it into a new instance of Microsoft Word. We want to be able to edit the text in the Word document, close the document and put the edited text back into the Rich Textbox control. This is the code sample:: : Private Sub cmdShowWord_Click(): Dim oDoc As Word.Document : : If MSWordOpen() Then: ' Add a New Document: Set oDoc = goWord.Documents.Add: ' Add Information to the Document: oDoc.Range.Text = txtSentence: : At this point, we want Word to "pause" so that the user can: edit the text that we placed into oDoc.Range.Text, disable: the Save button since we don't want to save the file to a: directory on the network, close the document and finally return: the text back into the Rich Text Box control on our VB form. : : ' Get Sentence Back From Word Document: txtSentence.Text = oDoc.Range.Text: : End If: End Sub: : We would appreciate any code that would help achieve our objective. Thank you.: :

[green]'Recognising that word has been closed inside this procedure - this may be unnecessary[/green] WordHasBeenClosed = False [green]'Make sure[/green] Do While Not WordHasBeenClosed DoEvents [green]'Let's the system DoWhatItWants[/green] Loop MsgBox "Word has been closed"

Private Sub myWord_DocumentBeforeSave(ByVal Doc As Word.Document, SaveAsUI As Boolean, Cancel As Boolean) If Doc.Name = oDoc.Name Then [green]'If you want to let work with another documents[/green] MsgBox "It's not possible to save document" Cancel = True End IfEnd Sub

Private Sub myWord_Quit() [green]'This may be not necessary[/green] WordHasBeenClosed = True [green]'Pausing[/green]End Sub[/code]Hope, this will help..