Consulting

Results 1 to 2 of 2

Thread: Solved: Get data from documents from a table to create spreadsheet

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    9
    Location

    Solved: Get data from documents from a table to create spreadsheet

    Another Novice here,
    Hello all and thank you in advance for any help you can give me.

    I have a several word documents that contain tables of data that I would like to see in a spreadsheet.

    The word documents have simple (same sized) tables, but sometimes there are multiple tables.

    I just want the data from the tables in a sreadsheet so I can work with it there.

    Here is what I have so far, the code asks for a folder where the documents can be found then it should go through each doc file and pull out data in every other field in the table. (skip any data that is not in a table). Paste the data to one spreadsheet.

    I dont know if it would be better for the code to paste data to the spreadsheet as it goes along, or paste it all at the end.

    Has anyone done something like this before. Any help would be appreciated.


    Sub TrackMST2()
    Dim appExcel As Object
    Dim objSheet As Object
    Dim tab2, tab4, tab6, tab8, tab10, tab12, tab14, tab16, tab18, tab20 As String
    Dim tab22, tab24, tab26, tab28, tab30, tab32, tab34, tab36, tab38, tab40 As String
    Dim GetFolderName As String
    Dim Prompt As String
    Dim Title As String
    Dim Path As String
    Dim FileName As String
    Dim MyResponse As VbMsgBoxResult
    Dim WrkFile As Document

    'SELECT FOLDER TO USE
    Prompt = "Lets start by selecting the folder containing the word docs we will use."
    Title = "Select a Folder"
    MsgBox Prompt, vbInformation, Title

    With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = OpenAt
    .Show
    For lCount = 1 To .SelectedItems.Count
    GetFolderName = .SelectedItems(lCount)
    Next lCount
    End With

    'Loop through all word documents
    FileName = Dir(GetFolderName & "\*.doc", vbNormal)
    Do Until FileName = ""
    On Error Resume Next
    '*******Here is where I know I have a problem with code*******
    Set aRange = FileName.Range
    With aRange.Table(1)
    Do
    Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst,
    Count:=1, Name:=""
    Selection.MoveRight Unit:=wdCell, Count:=2
    tab2 = Selection

    On Error GoTo 0
    FileName = Dir()

    Loop
    End With
    Loop
    End Sub

  2. #2
    VBAX Regular
    Joined
    Nov 2007
    Posts
    9
    Location
    moved to word help

Posting Permissions

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