By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

Extract text from a Word doc

P: n/a
How can I open a word doc and extract the text as text without any
formatting characters??

--
Barry Fitzgerald
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Barry,

Office
http://support.microsoft.com/default...b;EN-US;311452

http://msdn.microsoft.com/office/

Pia Download
http://www.microsoft.com/downloads/d...displaylang=en

Have a look at those pages

I think you find it there.

Cor
Nov 20 '05 #2

P: n/a
* "Barry" <ba*****@home.com> scripsit:
How can I open a word doc and extract the text as text without any
formatting characters??


Add a reference to the "Microsoft Word 10.0 Object Library"
COM component and use thide code:

\\\
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
Dim objWord As Word.ApplicationClass
Dim strText As String
objWord = New Word.Application()
With objWord
.Visible = False
.Documents.Open( _
Application.StartupPath & "\cookies.doc", _
, _
True _
)
.WordBasic.EditSelectAll()
.WordBasic.SetDocumentVar( _
"MyVar", _
.ActiveDocument.ActiveWindow.Selection.Text _
)
strText = .WordBasic.GetDocumentVar("MyVar")
TextBox1.Text = _
InsertNewLineChars(Strings.Left(strText, Len(strText) - 1))
.Documents.Close(0)
.Quit()
End With
End Sub

Private Function InsertNewLineChars( _
ByVal strText As String _
) As String
Dim pos As Integer, l As Integer
pos = 1
Do While pos < Len(strText)
l = Strings.InStr(pos, strText, vbCr)
If l = 0 Then Exit Do
strText = _
Strings.Left(strText, l - 1) & vbCrLf & _
Mid(strText, l + 1)
pos = l + 2
Loop
Return strText
End Function
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

P: n/a
Thanks, I think that will help me out enough.

--
Barry Fitzgerald
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Hi Barry,

Office
http://support.microsoft.com/default...b;EN-US;311452

http://msdn.microsoft.com/office/

Pia Download
http://www.microsoft.com/downloads/d...displaylang=en
Have a look at those pages

I think you find it there.

Cor

Nov 20 '05 #4

P: n/a
* "Barry" <ba*****@home.com> scripsit:
Thanks, I think that will help me out enough.


I hope you didn't forget to take a look at the "ready-to-be-copied"
solution I posted ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.