+ Reply to Thread
Results 1 to 5 of 5

VBA to fetch information from multiple word document to place in Excel spreadsheet

  1. #1
    Registered User
    Join Date
    05-27-2021
    Location
    Los Angeles, CA
    MS-Off Ver
    Office 365, Exl Version 2104
    Posts
    3

    Question VBA to fetch information from multiple word document to place in Excel spreadsheet

    Hi Everyone,
    We have a client intake form that we use to record our initial contact information in word format. Every time this form is filled we save them at a specific folder our server. I would like write a VBA code in Excel document that allows me to fetch a list of information that was collected and filled on the table that is available in every (Word format) client intake form we have in the folder. I attached a snapshot of the information that I am trying to fetch from every word forms filled out and bring init to the Excel register (attached a snapshot also).

    I found the following VBA code online however first it asks me to locate the file every time I run it and secondly it bring nothing on the register and I could not find the way to make it work at all. Please see below;

    Sub GetFormData()

    Application.ScreenUpdating = False
    Dim wdApp As New Word.Application
    Dim wdDoc As Word.Document
    Dim CCtrl As Word.ContentControl
    Dim strFolder As String, strFile As String
    Dim WkSht As Worksheet, i As Long, j As Long
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    Set WkSht = ActiveSheet
    i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row

    strFile = Dir(strFolder & "\*.docx", vbNormal)
    While strFile <> ""
    i = i + 1
    Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
    j = 0
    For Each CCtrl In .ContentControls
    j = j + 1
    WkSht.Cells(i, j) = FmFld.Result
    Next
    End With
    wdDoc.Close SaveChanges:=False
    strFile = Dir()
    Wend
    wdApp.Quit
    Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
    Application.ScreenUpdating = True


    End Sub


    Function GetFolder() As String
    Dim oFolder As Object
    GetFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
    End Function

    .... I appreciate if you could help me do this task. Thank you in advance!
    Attached Images Attached Images

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA to fetch information from multiple word document to place in Excel spreadsheet

    Assuming each word doc has just one table, try this...
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-27-2021
    Location
    Los Angeles, CA
    MS-Off Ver
    Office 365, Exl Version 2104
    Posts
    3

    Re: VBA to fetch information from multiple word document to place in Excel spreadsheet

    Hi Dangelor,
    I appreciate the response. I have two tables in the form but I am only trying to extract the information from the first table. Would this work with word documents that have two tables in each?

  4. #4
    Registered User
    Join Date
    05-27-2021
    Location
    Los Angeles, CA
    MS-Off Ver
    Office 365, Exl Version 2104
    Posts
    3

    Re: VBA to fetch information from multiple word document to place in Excel spreadsheet

    Hi Dangelor,
    I appreciate the response. I have two tables in the form but I am only trying to extract the information from the first table. Would this work with word documents that have two tables in each?

  5. #5
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: VBA to fetch information from multiple word document to place in Excel spreadsheet

    Well, it's set to get the data from table #1. So, if it gives the wrong data, we can set it to table #2. Give the code a try and see what happens.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. get information from excel into a word document
    By ntambomvu in forum Excel General
    Replies: 1
    Last Post: 12-03-2020, 10:54 AM
  2. [SOLVED] Excel vba code to place text after a specific phrase found in word document
    By Madhut in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-05-2017, 05:44 AM
  3. VBA Excel data through button to specefic place in excisting word document
    By Dikkenek in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-25-2016, 04:03 AM
  4. Replies: 8
    Last Post: 10-20-2012, 06:51 AM
  5. Copy information from VBA userform to multiple place in a MS word template
    By Jurjen Bakker in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2012, 07:18 AM
  6. Adding Excel Information Into a Word Document
    By dbirchum in forum Excel General
    Replies: 6
    Last Post: 04-27-2007, 04:25 PM
  7. [SOLVED] How do I merge excel information with a word document?
    By Dawn in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-15-2005, 11:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1