
Extracting Word Doc Titles using VB....code examples
Hello
Any of you out there had any experience of extracting title and other such
properties from Word Documents using OLE Automation.??
I tried using the following .......
Dim WordObj As Object
Set WordObj = CreateObject("Word.Basic")
sTmp = WordObj.DocumentPropertyName$(1) ' gets 1st property name.
and we find stmp = "Title"
which is great because all you should need to do then is call
sTitle = WordObj.GetDocumentProperty(1)
or
sTitle = WordObj.GetDocumentProperty(WordObj.DocumentPropertyName$(1))
However I only seem to get error when ever I try to call this code.
On investigation the WordBaisc help seemed to think that the data type is
wrong. (awkward since Word Basic only has String and Numeric)
casting with CSTR still raised the obscure word basic err casting to an
INT with CINT raised a type mismatch err 13 error which meant the returning
data type had to be a string
Confused I am because I could write the same code using word basic, in word
and it worked just fine.!
Here is the example code I used.. if any one has a idea on how to solve
this I would be grateful
Thanks
Alex O.
Dim WordObj As Object
Set WordObj = CreateObject("Word.Basic")
For i = 1 To WordObj.CountDocumentProperties()
sPropertyName = WordObj.DocumentPropertyName$(i)
sPropertyValue = WordObj.GetDocumentProperty$(sPropertyName, 0)
Debug.Print sPropertyName
Debug.Print sPropertyValue
Next
here is some extras I found useful
'IS IT STRING date or number 0 for string 1 for number
If WordObj.DocumentPropertyType(sPropertyName) = 0 Then
If WordObj.documentpropertyexists$(sPropertyName) = 0 Then
sPropertyValue =
WordObj.GetDocumentProperty$(sPropertyName, 0)
End If
End If
sPropertyValue = WordObj.GetDocumentProperty$(sPropertyValue, 1)
'CLng(1))
Debug.Print sPropertyValue