Before you go much further with this, may I tactfully suggest you read a
recent text on VB. The code you're posted looks like it was learnt on the
fly, a long time ago. It is horribly bug-ridden, and seems to rest on a
number of wrong assumptions about how VB and Word work. Eg
> 2 Dim doc, temp, temp1 As Word.Document
You might think you have declared three variables of type Word.document; but
only temp1 is a word.document -- the others are variants.
Since you declare wordapp as 'new', then word will always be running when
you test it. That has nothing to do with its visibility, or whether there
happens to be an active document. To test whether Word is running --
Dim WordApp as Word.Application
on error resume next
Set WordApp = Word.Application
on error goto 0
If WordApp is nothing then
... Word was not running
set WordApp = new Word.Application
else
... Word was running
set doc = WordApp.ActiveDocument
end if
Your textbox text appears in a new document because you put it there --
> 32 temp = wordapp.Documents.Add()
> 33 doc = wordapp.ActiveDocument
line 32 creates a new document. The newly-created document becomes the
active document. Line 33 does nothing very much: since doc is actually a
variant, and you assign it to the activedocument without using 'set', you're
actually assigning the content of the document (which is nothing, since it's
a new document). You fill the new document with the content of your textbox
at
> Hi There
>
[quoted text clipped - 71 lines]
>
> Immy
aalaan - 04 Dec 2006 05:40 GMT
Sorry about all this bad news, but another issue is you *can't* write a
program to proof read. That is always a manual process that consists of
checking the final camera ready copy word-for-word against the latest raw
text. You can only really do this well by reading backwards one person to
another.
> Before you go much further with this, may I tactfully suggest you read a
> recent text on VB. The code you're posted looks like it was learnt on the
[quoted text clipped - 116 lines]
>>
>> Immy
Immy - 05 Dec 2006 03:53 GMT
Hi Jezebel
Thanks for answering my post.
I tried your code on my application however it seems that my vb application
cannot detect an active Word document even though one has been opened.
I have adapted your suggestions and modified my code based on those
suggestions. The code is now as follows:
Dim wordapp As Word.Application
Dim doc As Word.Document
'open the document
'Determinig whether Word is running or not
On Error Resume Next
wordapp = New Word.Application
On Error GoTo 0
If wordapp Is Nothing Then
wordapp = CreateObject("Word.Application")
Else
'word is running
doc = wordapp.ActiveDocument
doc.Content.Text = RichTextBox2.Text
End If
I have assigned ‘doc’ to wordapp.ActiveDocument as you suggested. However,
when I run the code an error message appears that says “no Word document
open,” which in fact one is open.
I am using the 2005 Express Edition of Visual Basic and running MS Office
2007. I have tried using the set keyword for setting wordapp to
Word.Application. I don’t think this is required any more in the new version
of Visual Basic.
I would be please to hear your ideas on solving this problem.
> Before you go much further with this, may I tactfully suggest you read a
> recent text on VB. The code you're posted looks like it was learnt on the
[quoted text clipped - 112 lines]
> >
> > Immy
Jezebel - 05 Dec 2006 04:20 GMT
More that you need to relearn about VBA: if you're assigning an object to a
variable, you need to use the 'set' keyword --
set doc = wordapp.ActiveDocument
> Hi Jezebel
>
[quoted text clipped - 165 lines]
>> >
>> > Immy