Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA: Convert word document to Word Form

    Hi,

    This is my first post.
    I need to convert word documents to Word Form documents.

    In the source document, Labels are followed by data. Name: Jack Randy and so on. I need to convert the document to form, so that we can extract the values from the document programatically.

    Consider attached files:
    1. Jack Randy_123987.doc - Sample Input File
    2. Jack Randy_123987_form.doc - Required output

    Someone mentioned that this could be achieved using VBA. Could you please give pointers as to how this can be done.

    If alternatively their is better approach, do let me know.

    Thank you.

    MK
    Attached Files Attached Files

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Although I haven't tried these tools, I think the following links will more than answer your question. These links are related to each other but may present different information that is relevant to you.
    http://gregmaxey.mvps.org/word_tip_p...form_data.html
    http://www.gmayor.com/ExtractDataFromForms.htm
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Andrew for the quick response.

    My requirement is a little different. Their are thousands of existing documents (not utilizing forms) from which data needs to be extracted. I would like to know the best way to convert existing documents - to forms - so that I can extract data automatically - utilizing the tools suggested by you.

    regards

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    If your existing documents are not already using the form fields then your real problem is knowing where in the document each nugget of information exists. We can't really solve this without seeing sample documents to see if there is a consistent pattern across all documents for where the 'fields' are located. We can show you how to build code to extract the data from one document but if the next document puts it's data in other places then the code will fail spectacularly - Garbage In/Garbage Out.

    It sounds like extracting this information into fields is not the primary task - the primary task is identifying what information belongs in each field and what to do when that information is not found. If you need to parse thousands of documents then you better hope that each document has a VERY consistent layout and nobody edited the original source file too much.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Andrew. This is inline with my understanding. Probably we can add error handler in case few documents deviate from standard format, and then can tweak the code a little bit.

    I had attached the source document in my original posting.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    faltumk
    Your original source is all well and good but a document with that exact same structure is likely to exist exactly one time. Anyway, despite the doom and gloom, we can capture the data as long as that data is consistent.

    I wouldn't bother with converting individual items into mergefields - I would simply capture every 'Paragraph' to a database and then jettison the columns of paragraphs that don't contain useful information. The following code dumps this information into your Immediate Window and could then be pasted into Excel. You could set this sort of thing up as a batch to populate a database and then throw away the fields with useless data you would be left with the good fields which you could rename as you see fit.
    Code:
    Sub GetAPara()
      Dim aPara As Paragraph
      Dim iCounter As Integer
      For iCounter = 1 To ActiveDocument.Paragraphs.Count
        Debug.Print "Field " & iCounter & vbTab & Trim(ActiveDocument.Paragraphs(iCounter).Range.Text)
      Next iCounter
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •