Solved

MS Doc to Text convert

Posted on 2002-03-04
3
153 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now