Solved

MS Doc to Text convert

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 41
Using "ScreenUpdating" 6 84
passing a value with stream reader AFTER a ";" 3 84
VB 6 error 5 in windows 10 but not in XP 7 67
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

733 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