Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2006, 04:47 PM
Registered User
 
Join Date: Feb 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Paul_Tic
Default Retrieve data from word table

Hi,

I need to extract from a table in a word document into my database and am not sure where to start.

Any advice on this would be great!

Paul
 
Old February 27th, 2006, 09:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Paul

I suspect your best bet would be to convert the Word table into a delimited text file, or an excel spreadsheet, and import one or the other of those formats.

Bob

 
Old May 26th, 2006, 11:31 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I ran into a similar problem yesterday and found some good info on a Google Group...

I savaged the code quite severely to get it to work in my particular situation, mostly because I was extracting it from straight Word Text, not a table, but for what it is worth...

If you want to write code to do it, here is an example that just creates a
message box for each cell in the table showing the value. This could be
converted to create a record in Access and you could adapt it to do this for
a number of documents, each with 1 or more tables.
Is this a route you might pursue?

Private Sub cmdExtract_Click()


    On Error GoTo Err_Handler


    Dim strPath As String
    Dim strValue As String
    Dim wdApp As Object 'Word.Application
    Dim wdDoc As Object 'Word.Document
    Dim wdTbl As Object 'Word.Table
    Dim wdRow As Object 'Word.Row
    Dim wdCol As Object 'Word.Column
    Dim wdCell As Object 'Word.Cell


    strPath = "C:\Example.doc"


    Set wdApp = CreateObject("Word.Application")


    Set wdDoc = wdApp.Documents.Open(strPath)


    If wdDoc.Tables.Count > 0 Then


        Set wdTbl = wdDoc.Tables(1)


        For Each wdRow In wdTbl.Rows


            For Each wdCol In wdTbl.Columns


                strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text


                If Len(strValue) > 2 Then
                    strValue = Left$(strValue, Len(strValue) - 2)
                Else
                    strValue = ""
                End If


                MsgBox strValue


            Next wdCol


        Next wdRow


    End If


    MsgBox "Done", vbInformation


Exit_Handler:


    On Error Resume Next


    If Not wdDoc Is Nothing Then
        wdDoc.Close
        Set wdDoc = Nothing
    End If


    If Not wdApp Is Nothing Then
        wdApp.Quit
        Set wdApp = Nothing
    End If


    Exit Sub


Err_Handler:
    MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
    Resume Exit_Handler


End Sub




Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve Index Status of a table muralidharan.d SQL Server 2005 1 June 6th, 2008 04:13 PM
Retrieve different data from same table /field W052107 Visual Studio 2005 7 August 6th, 2007 10:40 AM
retrieve word/excel from database as binary fitchic77 .NET Framework 2.0 1 December 7th, 2004 03:00 PM
How to retrieve data from an array to a table? penta Access 4 September 22nd, 2004 03:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.