[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

MS Doc to Text convert

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
kerzner
Asked:
kerzner
1 Solution
 
eosuCommented:
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
 
sridhar_PJCommented:
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
 
kerznerAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now