* "Barry" <ba*****@home.c om> 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.EventArg s _
) Handles MyBase.Load
Dim objWord As Word.Applicatio nClass
Dim strText As String
objWord = New Word.Applicatio n()
With objWord
.Visible = False
.Documents.Open ( _
Application.Sta rtupPath & "\cookies.d oc", _
, _
True _
)
.WordBasic.Edit SelectAll()
.WordBasic.SetD ocumentVar( _
"MyVar", _
.ActiveDocument .ActiveWindow.S election.Text _
)
strText = .WordBasic.GetD ocumentVar("MyV ar")
TextBox1.Text = _
InsertNewLineCh ars(Strings.Lef t(strText, Len(strText) - 1))
.Documents.Clos e(0)
.Quit()
End With
End Sub
Private Function InsertNewLineCh ars( _
ByVal strText As String _
) As String
Dim pos As Integer, l As Integer
pos = 1
Do While pos < Len(strText)
l = Strings.InStr(p os, strText, vbCr)
If l = 0 Then Exit Do
strText = _
Strings.Left(st rText, l - 1) & vbCrLf & _
Mid(strText, l + 1)
pos = l + 2
Loop
Return strText
End Function
///
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>