I
Immy
Hi There
I seem to be having some problems with my coding and am looking for some help.
I am designing an application in VB 2005 use for editing spelling and
grammar errors in MS Word documents. The application would check and edits,
as well as proof read MS Word documents.
The following is a snippet of the code I am working on:
1 Dim wordapp As New Word.Application
2 Dim doc, temp, temp1 As Word.Document\3
3
4
5
6 'Determinig whether Word is running or not
7 While wordapp.Visible = True
8 doc = wordapp.Templates.Application.ActiveDocument
9
10 wordapp.ActiveDocument.Content.Text = RichTextBox2.Text
11 'doc = wordapp.ActiveDocument
12 'wordapp.ActiveDocument.Content.Text = RichTextBox2.Text
13 ToolStripStatusLabel2.Text = doc.Words.Count
14
15 End While
16
17 If wordapp.Visible = False Then
18 wordapp.Visible = True
19 If wordapp.Visible = True Then
20 temp = wordapp.ActiveDocument
21 End If
22 temp = wordapp.Documents.Add()
23 temp = wordapp.ActiveDocument
24 temp.Content.Text = RichTextBox2.Text
25
26 'doc = wordapp.ActiveWindow
27 'wordapp.Selection.TypeText(RichTextBox2.Text)
28 'wordapp.ActiveDocument.Content.Text = RichTextBox2.Text
29 ToolStripStatusLabel2.Text = doc.Words.Count
30
31 ElseIf wordapp.Visible = True Then
32 temp = wordapp.Documents.Add()
33 doc = wordapp.ActiveDocument
34 'temp = doc
35 'doc.Content.Text = RichTextBox2.Text
36 'doc = wordapp.ActiveDocument 'set doc to activedocument
37 wordapp.Selection.TypeText(RichTextBox2.Text)
38 'ActiveDocument.Content.Text = RichTextBox2.Text
39 ToolStripStatusLabel2.Text = doc.Words.Count
40 End If
The problem appear in line 17 -24 where I am checking to see whether a MS
Word document is open or not. The doccument could be one currently used by
the user or one that have been saved or just a new document.
My question is as follows:
• In line 17 – 21 of my code, I am attempting to see whether or not the MS
Word application is running or not. If the application is runninng and a file
is use, I want that file assign to ActivateDocument.
• On my form there are two rich text boxes: one is for displaying the
paragraph containing the spelling and writing errors. The second, displays
the whole document. My problem is whenever I enter text into the text box,
instead of that typed text into the activated document it appears in a new MS
Word Document.
I would be grateful if anyone can advice me how to overcome this problem.
Thanks,
Immy
 
I seem to be having some problems with my coding and am looking for some help.
I am designing an application in VB 2005 use for editing spelling and
grammar errors in MS Word documents. The application would check and edits,
as well as proof read MS Word documents.
The following is a snippet of the code I am working on:
1 Dim wordapp As New Word.Application
2 Dim doc, temp, temp1 As Word.Document\3
3
4
5
6 'Determinig whether Word is running or not
7 While wordapp.Visible = True
8 doc = wordapp.Templates.Application.ActiveDocument
9
10 wordapp.ActiveDocument.Content.Text = RichTextBox2.Text
11 'doc = wordapp.ActiveDocument
12 'wordapp.ActiveDocument.Content.Text = RichTextBox2.Text
13 ToolStripStatusLabel2.Text = doc.Words.Count
14
15 End While
16
17 If wordapp.Visible = False Then
18 wordapp.Visible = True
19 If wordapp.Visible = True Then
20 temp = wordapp.ActiveDocument
21 End If
22 temp = wordapp.Documents.Add()
23 temp = wordapp.ActiveDocument
24 temp.Content.Text = RichTextBox2.Text
25
26 'doc = wordapp.ActiveWindow
27 'wordapp.Selection.TypeText(RichTextBox2.Text)
28 'wordapp.ActiveDocument.Content.Text = RichTextBox2.Text
29 ToolStripStatusLabel2.Text = doc.Words.Count
30
31 ElseIf wordapp.Visible = True Then
32 temp = wordapp.Documents.Add()
33 doc = wordapp.ActiveDocument
34 'temp = doc
35 'doc.Content.Text = RichTextBox2.Text
36 'doc = wordapp.ActiveDocument 'set doc to activedocument
37 wordapp.Selection.TypeText(RichTextBox2.Text)
38 'ActiveDocument.Content.Text = RichTextBox2.Text
39 ToolStripStatusLabel2.Text = doc.Words.Count
40 End If
The problem appear in line 17 -24 where I am checking to see whether a MS
Word document is open or not. The doccument could be one currently used by
the user or one that have been saved or just a new document.
My question is as follows:
• In line 17 – 21 of my code, I am attempting to see whether or not the MS
Word application is running or not. If the application is runninng and a file
is use, I want that file assign to ActivateDocument.
• On my form there are two rich text boxes: one is for displaying the
paragraph containing the spelling and writing errors. The second, displays
the whole document. My problem is whenever I enter text into the text box,
instead of that typed text into the activated document it appears in a new MS
Word Document.
I would be grateful if anyone can advice me how to overcome this problem.
Thanks,
Immy