Solved

MS Doc to Text convert

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

20 Experts available now in Live!

Get 1:1 Help Now