Results 1 to 20 of 41

Thread: Solved: Excel macro to extract Word form data into Excel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Sorry, I chose the wrong dialogue. Change:
    With Application.Dialogs(xlDialogFindFile)
    to:
    With Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
    and change:
    StrFlNm = .Name
    to:
    StrFlNm = .SelectedItems(1)
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  2. #2
    The code is running fine now, the document I choose is opening and closing however no text is being transferred to the excel spreadsheet. I assume I would need to define the tags for the fields I wish to copy but I am not sure where to do that.

    Thanks for all your help so far!!

    Sub InsertFormfieldResults()
        Application.ScreenUpdating = False
        Dim lRow As Long, i As Long, j As Long, StrFlNm As String
        With Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
            SendKeys "%n *.doc ~"
            If .Show = True Then
                StrFlNm = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        Dim xlWkSht As Worksheet
        Set xlWkSht = ActiveSheet
        lRow = xlWkSht.Cells.SpecialCells(xlCellTypeLastCell).Row + 1
        Dim wdApp As New Word.Application
        Dim wdDoc As Word.Document
        wdApp.Visible = True
        Set wdDoc = wdApp.Documents.Open(Filename:=StrFlNm, AddToRecentFiles:=False)
        With wdDoc
            For i = 1 To .FormFields.Count
                xlWkSht.Cells(lRow + Int((i - 1) / 5), ((i - 1) Mod 5) + 1).Value = .FormFields(i).Result
            Next
            .Close SaveChanges:=False
        End With
        wdApp.Quit
        Set wdDoc = Nothing: Set wdApp = Nothing
        Application.ScreenUpdating = True
    End Sub

Posting Permissions

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