[AccessD] Scrape Word Part II

Bob Heygood bheygood at abestsystems.com
Sat Jun 11 10:28:36 CDT 2005


thanks for your response Marty.
I started out this time to use custom properties, but am backing away
because I can't see how to keep the info the user types in at my prompt in
the custom property.

think I'll go back to just a simple bookmark, though that is a hassle as it
is hard to capture particular info once in a cell of a Word table.




bob

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of MartyConnelly
Sent: Friday, June 10, 2005 9:17 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Scrape Word Part II


As to custom properties you could use the dsofiles.dll, it works for any
ole type file
mdb,doc,xls,ppt or whatever visio uses, this also works from vb.net,
doesn't require word be installed.
There is also code to search for text which might be modified for
bookmarks but
there are two types of word bookmarks.
http://www.word.mvps.org/faqs/macrosvba/WorkWithBookmarks.htm

You could try searching this site especially the links to other word
mvp's like cindy meister
I think you will have to poke around to find all the bits and pieces
http://word.mvps.org
or the main site
http://www.mvps.org


'See MSKB and Dsofile.exe Lets You Edit Office Document Properties from
Visual Basic and ASP
'Microsoft Knowledge Base Article - 224351
'and download dsofile.exe
'http://support.microsoft.com/?kbid=224351
'Add a reference (Tools | References in the VBE window) to it.
' depending on path where you have installed dsofile.dll
'Put the following in a new module and you should be OK

'Dsofile.dll lets you edit Office document properties without
'Office in Visual Basic .NET 2003 and in Visual Basic .NET 2002
'http://support.microsoft.com/?id=224351
'===========================================================
'http://www.word.mvps.org/faqs/macrosvba/WorkWithBookmarks.htm
Private oFilePropReader As DSOleFile.PropertyReader
Private oDocProp As DSOleFile.DocumentProperties

Public Sub GetPropsFromDirectory()
'this routine gets all doc files in a directory and shows Line Count and
author

Dim ffile As String
On Error Resume Next
'careful with above line
'this is Quick and Dirty used to avoid missing propereties on some filetypes
' this can be used with microsoft, doc, ppt, xls and mdb files
    ffile = Dir("c:\wordvba\*.doc")
    Do While ffile <> "" 'recursive search for sub directories can be
written
        If ffile <> "." And ffile <> ".." Then
            Set oFilePropReader = New DSOleFile.PropertyReader
            Set oDocProp = _
            oFilePropReader.GetDocumentProperties("c:\wordvba\" & ffile)
            MsgBox oDocProp.Name & " " & oDocProp.PageCount & _
               " pages " & oDocProp.Author
              With oDocProp
        Debug.Print "Name " & .Name
        Debug.Print "Application Name " & .AppName
        Debug.Print "Author " & .Author
        Debug.Print "Category " & .Category
        Debug.Print "Class Id " & .CLSID
        Debug.Print "Comments " & .Comments
        Debug.Print "Company " & .Company
        'Debug.Print "Custom " & .CustomProperties 'check index values
        Debug.Print "Create date " & .DateCreated
        Debug.Print "Last edited " & .DateLastEdited
        Debug.Print "Last printed " & .DateLastPrinted
        Debug.Print "Last saved " & .DateLastSaved
        Debug.Print "Contains Macros " & .HasMacros 'doesn't work with
ppt files
        'Debug.Print .Icon 'you can view thumbnail in picture object
        Debug.Print "Read only " & .IsReadOnly
        Debug.Print "Keywords " & .Keywords
        Debug.Print "Last edited by " & .LastEditedBy
        Debug.Print "Line Count " & .LineCount
        Debug.Print "Location " & .Location
        Debug.Print "Manager " & .Manager
        Debug.Print "Page Count " & .PageCount
        Debug.Print "Paragraphs "; .ParagraphCount
        Debug.Print "Program Id " & .ProgId
        Debug.Print "Revision No. " & .RevisionNumber
        Debug.Print "Slides "; .SlideCount
        Debug.Print "Subject " & .Subject
        Debug.Print "Title " & .Title
        Debug.Print "Version " & .Version
        Debug.Print "WordCount " & .WordCount
        Debug.Print "Char Cnt " & .CharacterCount
        Debug.Print " "
        End With
            ffile = Dir()
            Set oDocProp = Nothing
            Set oFilePropReader = Nothing

        End If
    Loop
End Sub

Here is some quick and dirty code that opens a Word doc from inside Access,
searches for the string "special code:" and sets a string variable equal to
the sentence that follows the code string. If your documents all have the
same string you can find that string and select words, sentences or
paragraphs that come after it. from  Jim Hale

Function LiftText()

Dim wd As Word.Application, strPhrase As String, strFindphrase As String
strFindphrase = "special code:"
Set wd = New Word.Application
wd.Documents.Open "C:\Test.doc"
wd.Visible = True
wd.Selection.Find.ClearFormatting
    With wd.Selection.Find
        .Text = strFindphrase
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    wd.Selection.Find.Execute
    wd.Selection.Start = wd.Selection.End
   Call wd.Selection.EndOf(wdSentence, wdExtend)
    strPhrase = wd.Selection
    MsgBox "Look what I found: " & strPhrase
    wd.ActiveDocument.Close
    wd.Quit
    Set wd = Nothing
End Function


Bob Heygood wrote:

>thanks Jim.
>I have looked before at Helen's code. Lots of great stuff there.
>
>bob
>
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Hale, Jim
>Sent: Wednesday, June 08, 2005 8:17 AM
>To: 'Access Developers discussion and problem solving'
>Subject: RE: [AccessD] Scrape Word Part II
>
>
>At the very bottom of this link Helen Feddema has some code that may help
>you.
>http://www.helenfeddema.com/CodeSamples.htm
>
>Jim Hale
>
>-----Original Message-----
>From: Bob Heygood [mailto:bheygood at abestsystems.com]
>Sent: Wednesday, June 08, 2005 8:35 AM
>To: Access Developers discussion and problem solving
>Subject: [AccessD] Scrape Word Part II
>
>
>Hello to the list,
>
>Well, my project is alive again. This time I have the luxury of being able
>to create the Word document from which I need to cull the info. I still
need
>to have a Word table but I can create bookmarks or whatever within the
table
>in the document.
>To recap I need to import 10 pieces of text from a Word document and store
>them in a mdb table.
>Jim Hale's code below worked really good except that we were pressed for
>time and did not ever get it to work in all areas of the Word doc.
>So my first question is how to search the Word doc to find the text,
>bookmarks, fields, custom properties or ????
>
>
>TIA,
>
>Bob Heygood
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Hale, Jim
>Sent: Monday, April 18, 2005 8:54 AM
>To: 'Access Developers discussion and problem solving'
>Subject: RE: [AccessD] Scrape Word
>
>
>Whatever it takes to get the job done! Sorry I couldn't be more help.
>Jim Hale
>
>-----Original Message-----
>From: Bob Heygood [mailto:bheygood at abestsystems.com]
>Sent: Monday, April 18, 2005 10:09 AM
>To: Access Developers discussion and problem solving
>Subject: RE: [AccessD] Scrape Word
>
>
>Thanks Jim
>I finally just ran the job as it took about 4 hours to process 256
>documents.
>it is a one time deal and the customer needed to have the results.
>
>your help was fantastic.
>
>bob
>
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Hale, Jim
>Sent: Friday, April 15, 2005 3:18 PM
>To: 'Access Developers discussion and problem solving'
>Subject: RE: [AccessD] Scrape Word
>
>
>I'll look at it some more on Monday. You might examine the selection object
>in the Word application. It has numerous properties and methods one or more
>of which should do the trick.
>Jim Hale
>
>-----Original Message-----
>From: Bob Heygood [mailto:bheygood at abestsystems.com]
>Sent: Friday, April 15, 2005 4:52 PM
>To: Access Developers discussion and problem solving
>Subject: RE: [AccessD] Scrape Word
>
>
>yes in a table cell.
>again your code is working super.
>but only grabs the first word, sometimes there is more than one word in the
>cell, and I would like to capture all of them.
>if you have thought, I would welcome it.
>
>
>again I tried to manipulate the code further but it acts very erratic when
>in a table cell.
>
>thanks for the great help.
>
>bob
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Hale, Jim
>Sent: Thursday, April 14, 2005 12:53 PM
>To: 'Access Developers discussion and problem solving'
>Subject: RE: [AccessD] Scrape Word
>
>
>So the data you want (including the search string) is in a table cell? In
>the code I sent you delete
>   wd.Selection.Start = wd.Selection.End
>   Call wd.Selection.EndOf(wdSentence, wdExtend)
>
>and replace with
>   wd.Selection.Next(Unit:=wdWord, Count:=1).Select
>
>Or if the entire string is returned you can replace the search string with
>an empty string "" using the following function:
>
>Function ReplaceString(strTextIn As String, strFind As String, strReplace
As
>String, fCaseSensitive As Boolean) As String
>
>  Dim strTmp As String
>  Dim intPos As Integer
>  Dim intCaseSensitive As Integer
>
>  intCaseSensitive = IIf(fCaseSensitive, 2, 1)
>
>  strTmp = strTextIn
>  intPos = InStr(1, strTmp, strFind, intCaseSensitive)
>
>  Do While intPos > 0
>    strTmp = Left$(strTmp, intPos - 1) & strReplace & Mid$(strTmp, intPos +
>Len(strFind))
>    intPos = InStr(intPos + Len(strReplace), strTmp, strFind,
>intCaseSensitive)
>  Loop
>
>  ReplaceString = strTmp
>
>End Function
>
>Jim Hale
>
>
>***********************************************************************
>The information transmitted is intended solely for the individual or
>entity to which it is addressed and may contain confidential and/or
>privileged material. Any review, retransmission, dissemination or
>other use of or taking action in reliance upon this information by
>persons or entities other than the intended recipient is prohibited.
>If you have received this email in error please contact the sender and
>delete the material from any computer. As a recipient of this email,
>you are responsible for screening its contents and the contents of any
>attachments for the presence of viruses. No liability is accepted for
>any damages caused by any virus transmitted by this email.
>
>
>--
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>***********************************************************************
>The information transmitted is intended solely for the individual or
>entity to which it is addressed and may contain confidential and/or
>privileged material. Any review, retransmission, dissemination or
>other use of or taking action in reliance upon this information by
>persons or entities other than the intended recipient is prohibited.
>If you have received this email in error please contact the sender and
>delete the material from any computer. As a recipient of this email,
>you are responsible for screening its contents and the contents of any
>attachments for the presence of viruses. No liability is accepted for
>any damages caused by any virus transmitted by this email.
>
>
>--
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>***********************************************************************
>The information transmitted is intended solely for the individual or
>entity to which it is addressed and may contain confidential and/or
>privileged material. Any review, retransmission, dissemination or
>other use of or taking action in reliance upon this information by
>persons or entities other than the intended recipient is prohibited.
>If you have received this email in error please contact the sender and
>delete the material from any computer. As a recipient of this email,
>you are responsible for screening its contents and the contents of any
>attachments for the presence of viruses. No liability is accepted for
>any damages caused by any virus transmitted by this email.
>
>
>
>

--
Marty Connelly
Victoria, B.C.
Canada



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list