How to programmatically convert Word doc to ASCII?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Looking for a method to programmatically convert (using vB) a Word doc to it's ASCII equivalent. I understand I'll lose all formatting, and that's okay

Anyone out there have ideas

Thaks

Dennis
 
* =?Utf-8?B?RGVubmlz?= said:
Looking for a method to programmatically convert (using vB) a Word doc to it's ASCII equivalent. I understand I'll lose all formatting, and that's okay.

ASCII will loose some special characters too, but maybe this snippet
points you into the right direction:

Add a reference to the "Microsoft Word 10.0 Object Library"
COM component and use this 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
///
 
This looks great! Since I am a relative neophyte in vB, I would like to know how I should invoke this routine. Do I have a MAIN that opens a file for INPUT/BINARY? Once opened, how do I pass the necessary information to the routine? Additionally, exaclty what *is* the "necessary information"

Thanks a millio

Dennis
 
Back
Top