Solved

MS Doc to Text convert

Posted on 2002-03-04
3
157 Views
Last Modified: 2010-05-02
Hi,

I need VB code to convert an MS Doc file to text. I have written something like what is below, but it is too amateurish. It has problems like locking up, and showing the Word, which I don't want, and I can't make it save as text.

I need a command-line executable, compiled in VB. Who could help?

Thank you.

Sub main()    
    Dim wdApp As Object
    Set wdApp = New Word.Application
    Dim fileName As String
    Dim doc As Word.Document
    inFileName = "file.doc"
    Set doc = wdApp.Documents.Open(inFileName)
    Dim outFileName As String
    outFileName= "file.txt"
    doc.SaveAs (fileName = outFileName)
    doc.Close
End Sub
0
Comment
Question by:kerzner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Expert Comment

by:eosu
ID: 6841075
Have done something like this  - but you realise that you will loose tables, graphics, and so on.  Only the straight text would be pulled out...  Haven't compiled what is below, so there might be typos...


    dim x as new Word.Application

    x.Documents.Open txtFileName.Text
    open "C:\worddoc.txt" for output as #1

    For i = 1 To x.ActiveDocument.Paragraphs.Count - 1
        str = x.ActiveDocument.Paragraphs(i)
        print #1, str
    Next
   
    x.Documents.Close False
    close #1
    set x = nothing
0
 
LVL 3

Accepted Solution

by:
sridhar_PJ earned 300 total points
ID: 6841077
Hi,
Same way but slightly enhanced,

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=4217&lngWId=1

Hope this help u.
Regards
Sridhar
0
 
LVL 1

Author Comment

by:kerzner
ID: 6843121
I have already done something like it, and it works.

However, fair is fair and the answer gets 300 points, especially because it is impossible to check whether I already have it, and it is nice for me to check my solution.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question