C
Co
Hi All,
I tried a new code to read the first page of a word document and save
the content to a richttextbox.
The code I created just reads the first character of the first page
instead of the first page:
Function ReadWordDocument(ByVal sPathName As String) As String
Dim wdToepassing As New Word.Application()
Dim wdDoc As Word.Document
Dim oBuiltInProps As Object
Dim strValue As String
Dim oRange As Word.Range
Dim PgDepart As Long
Try
wdDoc = wdToepassing.Documents.Open(sPathName)
'Get the Built-in Document Properties collection.
oBuiltInProps = wdDoc.BuiltInDocumentProperties
'Get the value of the Author property
strValue = oBuiltInProps.Item("Author").Value
PgDepart = wdToepassing.Selection.Range.Start
'Move the insertion pointer to the bottom of the first
page
oRange = wdDoc.Range(Start:=PgDepart, End:=PgDepart + 1)
oRange.Copy()
ReadWordDocument = _
CStr(System.Windows.Forms.Clipboard.GetDataObject.GetData
(DataFormats.Text))
Catch oException As Exception
MessageBox.Show(oException.Message)
ReadWordDocument = ""
Finally
oRange = Nothing
wdDoc = Nothing
wdToepassing.ActiveWindow.Close()
wdToepassing = Nothing
End Try
End Function
regards
Marco
The Netherlands
I tried a new code to read the first page of a word document and save
the content to a richttextbox.
The code I created just reads the first character of the first page
instead of the first page:
Function ReadWordDocument(ByVal sPathName As String) As String
Dim wdToepassing As New Word.Application()
Dim wdDoc As Word.Document
Dim oBuiltInProps As Object
Dim strValue As String
Dim oRange As Word.Range
Dim PgDepart As Long
Try
wdDoc = wdToepassing.Documents.Open(sPathName)
'Get the Built-in Document Properties collection.
oBuiltInProps = wdDoc.BuiltInDocumentProperties
'Get the value of the Author property
strValue = oBuiltInProps.Item("Author").Value
PgDepart = wdToepassing.Selection.Range.Start
'Move the insertion pointer to the bottom of the first
page
oRange = wdDoc.Range(Start:=PgDepart, End:=PgDepart + 1)
oRange.Copy()
ReadWordDocument = _
CStr(System.Windows.Forms.Clipboard.GetDataObject.GetData
(DataFormats.Text))
Catch oException As Exception
MessageBox.Show(oException.Message)
ReadWordDocument = ""
Finally
oRange = Nothing
wdDoc = Nothing
wdToepassing.ActiveWindow.Close()
wdToepassing = Nothing
End Try
End Function
regards
Marco
The Netherlands