Concerting word document to text document 
Author Message
 Concerting word document to text document

I have a word 97 document which we will call test.doc.  I want to be able to
run  a VB executable which will convert the document from a word document
(.doc) to a text document (.txt)  What I would like is the code that I can
use to do this.

--== Sent via Deja.com http://www.*-*-*.com/
---Share what you know. Learn what you don't.---



Sun, 28 Oct 2001 03:00:00 GMT  
 Concerting word document to text document
Do you have Word?  If not, I imagine it would be very difficult as you would
need to learn the internals of the MS Word DOC format which aren't public.

If you do, then it should be easy to do through OLE.  Basically, using the
OLE interface you can do through VB code just about anything you can do
inside Word, including saving a document as text.  If you aren't familiar
with programming with OLE it might seem intimidating--but it's worth
learning.

I think the help files that come with Word include info on using the object
library and you can actually figure out pretty quickly from these what you
need to do.  I think you could do what you want in a dozen lines of code.

Joel Moore

Quote:

>I have a word 97 document which we will call test.doc. I want to be able to
>run  a VB executable which will convert the document from a word document
>(.doc) to a text document (.txt)  What I would like is the code that I can
>use to do this.

>--== Sent via Deja.com http://www.deja.com/ ==--
>---Share what you know. Learn what you don't.---



Sun, 28 Oct 2001 03:00:00 GMT  
 Concerting word document to text document
I may not have explained myself properly.  I have a doocument called test.doc
which is sitting in a directory on the file server.  I want to be able to run
a VB executable which will convert the file from .doc format to .txt format.
I would like to do this without being in Word at the time.  Joel thanks for
your assistance so far.



Quote:
> Do you have Word?  If not, I imagine it would be very difficult as you would
> need to learn the internals of the MS Word DOC format which aren't public.

> If you do, then it should be easy to do through OLE.  Basically, using the
> OLE interface you can do through VB code just about anything you can do
> inside Word, including saving a document as text.  If you aren't familiar
> with programming with OLE it might seem intimidating--but it's worth
> learning.

> I think the help files that come with Word include info on using the object
> library and you can actually figure out pretty quickly from these what you
> need to do.  I think you could do what you want in a dozen lines of code.

> Joel Moore


> >I have a word 97 document which we will call test.doc. I want to be able to
> >run  a VB executable which will convert the document from a word document
> >(.doc) to a text document (.txt)  What I would like is the code that I can
> >use to do this.

> >--== Sent via Deja.com http://www.deja.com/ ==--
> >---Share what you know. Learn what you don't.---

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


Sun, 28 Oct 2001 03:00:00 GMT  
 Concerting word document to text document
My original post still applies.  If the machine you are running the VB
app on does NOT have MS Word installed then you have to know the MS Word
DOC format so you can figure out what's in it and manually translate it
into text.

If Word IS installed on the machine running the app then you can take
advantage of the OLE Automation interface Word supplies.  You don't have
to start Word manually.  You don't even have to show it.  It's all done
through code in the VB app.  You essentially use all of Word's
functionality through function calls to a MS Word object that exists
entirely in your code.

It might be fairly advanced.  I'm not sure what kind of experience you
have but it's something worth learning because it is an extremely
powerful tool.  Many commercial programs provide a OLE interface that
allows people to manipulate the software programmatically.  So you can
create custom applications use the power provided by other software.

If you were looking for a function in VB that can read a MS Word DOC then
you are out of luck.

Good luck,

Joel Moore


Quote:
> I may not have explained myself properly.  I have a doocument called test.doc
> which is sitting in a directory on the file server.  I want to be able to run
> a VB executable which will convert the file from .doc format to .txt format.
> I would like to do this without being in Word at the time.  Joel thanks for
> your assistance so far.



> > Do you have Word?  If not, I imagine it would be very difficult as you would
> > need to learn the internals of the MS Word DOC format which aren't public.

> > If you do, then it should be easy to do through OLE.  Basically, using the
> > OLE interface you can do through VB code just about anything you can do
> > inside Word, including saving a document as text.  If you aren't familiar
> > with programming with OLE it might seem intimidating--but it's worth
> > learning.

> > I think the help files that come with Word include info on using the object
> > library and you can actually figure out pretty quickly from these what you
> > need to do.  I think you could do what you want in a dozen lines of code.

> > Joel Moore


> > >I have a word 97 document which we will call test.doc. I want to be able to
> > >run  a VB executable which will convert the document from a word document
> > >(.doc) to a text document (.txt)  What I would like is the code that I can
> > >use to do this.

> > >--== Sent via Deja.com http://www.deja.com/ ==--
> > >---Share what you know. Learn what you don't.---

> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---



Sun, 28 Oct 2001 03:00:00 GMT  
 Concerting word document to text document

Quote:

> I have a word 97 document which we will call test.doc.  I want to be able to
> run  a VB executable which will convert the document from a word document
> (.doc) to a text document (.txt)  What I would like is the code that I can
> use to do this.

> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---

IF you have Word installed on your machine

Create a reference to Microsoft Word 8.0 etc

The code is

Option Explicit

Private m_objWord As Word.Application

Private Sub Command1_Click()

    Set m_objWord = CreateObject("Word.Application")
    With m_objWord
        .Documents.Open "YourDocument.doc"
        .ActiveDocument.SaveAs "YourDocument.txt", wdFormatText
        .ActiveDocument.Close
        .Quit
    End With
    Set m_objWord = Nothing
End Sub

Of course, you'll have to add your error handling.



Mon, 05 Nov 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Saving page breaks from Word documents to text documents

2. Cutting a full Word document and pasting it in another Word Document

3. Accessing XML document from a Word document

4. Print a word document built from multiple sub documents using the RD tag

5. Mailmerge document restored to normal document (Word 2000)

6. (Q211727) Mail merge document restored to normal document - Word 2000

7. Trouble Opening a Word Document with VB.NET,Open member not found in Documents

8. Help. Reading/displaying/printing Word Documents/RTF documents

9. getting a document description from a word document

10. Generating word document files from embedded documents in Access or SQL Server DB.

11. populating document properties from text in document

12. finding text in a document and split document

 

 
Powered by phpBB® Forum Software