Extracting Word Doc Titles using VB....code examples 
Author Message
 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



Tue, 18 Jul 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Extracting title from a Word Document

2. extract text from pocket word doc???urgent!

3. Convert Word doc to VB Code?

4. Extracting images to file from Word using VB automation

5. How to print Word Doc using VB

6. Opening a Word97 doc as a copy with no doc title

7. VB.Net using a Word doc object - copying in text w/ a hard return

8. Using Word Object to merge doc from VB

9. find/replace in a Word Doc using word object and vbscript

10. Using Title Doc Property As FileName When Saving Document

11. Printing docs thru Word 97 using VB/DDE - an example

12. Does anyone have any VB Example code using the CreateProcessAsUser API

 

 
Powered by phpBB® Forum Software