paulv_2005
New member
- Joined
- Jul 30, 2007
- Messages
- 1
- Programming Experience
- 1-3
I am using VB.Net 2 and trying to extract text from a word document including the document title.
The document title is a built in property wdPropertyTitle
What I find is that I can get the text of the word document but when I try to get the title using :
Dim strTitle As String = WordDoc.BuiltInDocumentProperties(Microsoft.Office.Interop.Word.WdBuiltInProperty.wdPropertyTitle).Value()
It says "Option Strict On disallows late binding"
If it set Option Strict to Off, it works correctly, but how do I make it work with Option strict On
'-----------------------------------------------------------
Dim WordApp As Microsoft.Office.Interop.Word.Application
Dim WordDoc As Microsoft.Office.Interop.Word.Document
Try
WordApp = CType(CreateObject("Word.Application"), Microsoft.Office.Interop.Word.Application)
WordApp.Visible = False
'LOAD WORD FILE INTO OBJECT
WordDoc = WordApp.Documents.Open("c:\temp\test.doc")
WordDoc.Activate()
WordDoc.ActiveWindow.Selection.WholeStory()
WordDoc.ActiveWindow.Selection.Copy()
Dim data As IDataObject = Clipboard.GetDataObject
Dim strText As String = data.GetData(DataFormats.Text).ToString
MessageBox.Show(strText)
'GET BUILT IN TITLE OF WORD DOCUMENT :
Dim strTitle As String = WordDoc.BuiltInDocumentProperties(Microsoft.Office.Interop.Word.WdBuiltInProperty.wdPropertyTitle).Value()
WordDoc.Close()
WordApp.Quit()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
The document title is a built in property wdPropertyTitle
What I find is that I can get the text of the word document but when I try to get the title using :
Dim strTitle As String = WordDoc.BuiltInDocumentProperties(Microsoft.Office.Interop.Word.WdBuiltInProperty.wdPropertyTitle).Value()
It says "Option Strict On disallows late binding"
If it set Option Strict to Off, it works correctly, but how do I make it work with Option strict On
'-----------------------------------------------------------
Dim WordApp As Microsoft.Office.Interop.Word.Application
Dim WordDoc As Microsoft.Office.Interop.Word.Document
Try
WordApp = CType(CreateObject("Word.Application"), Microsoft.Office.Interop.Word.Application)
WordApp.Visible = False
'LOAD WORD FILE INTO OBJECT
WordDoc = WordApp.Documents.Open("c:\temp\test.doc")
WordDoc.Activate()
WordDoc.ActiveWindow.Selection.WholeStory()
WordDoc.ActiveWindow.Selection.Copy()
Dim data As IDataObject = Clipboard.GetDataObject
Dim strText As String = data.GetData(DataFormats.Text).ToString
MessageBox.Show(strText)
'GET BUILT IN TITLE OF WORD DOCUMENT :
Dim strTitle As String = WordDoc.BuiltInDocumentProperties(Microsoft.Office.Interop.Word.WdBuiltInProperty.wdPropertyTitle).Value()
WordDoc.Close()
WordApp.Quit()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try