+ Reply to Thread
Results 1 to 4 of 4

Importing data from a Word 2010 form to Excel 2010.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-15-2011
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    3

    Importing data from a Word 2010 form to Excel 2010.

    Hi,
    My question is very similar to post: http://excel.bigresource.com/Track/excel-qh8tFqoE/

    I have excatly the same problem as mentioned above. I have very little experience with VBA, so you have to excuse me for asking obvious questions. The solution provided by Marble2009 doesn't work when I apply it on a Office 2010 computer.
    Application.FileSearch is not used in Office 2010 (as far as I could read), and there might be other problems.

    What I need is the following: multiple Word 2010 forms (docx) -> txt -> 1 excel spreadsheet.

    I guess I need help on how to update the code to Office 2010.

    Best regards,
    mlang

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Importing data from a Word 2010 form to Excel 2010.

    This is some code I wrote the other day to retrieve info from form fields on word docs saved in a particular folder which avoids using filesearch. It may be of use to you:

    Sub Log_Docs()
    
    Dim WdApp As Object, WdDoc As Object, blnAppOpen As Boolean, strDocName As String
    Dim lngWriteRow As Long, strDir As String
    
    blnAppOpen = True
    strDir = "C:\Returned Docs\"
    
    If MsgBox("Data will be retrieved from all Word documents in this folder:" & vbCrLf & vbCrLf & _
        strDir & vbCrLf & vbCrLf & "Do you want to continue?", vbYesNo + vbQuestion) = vbNo Then
        Exit Sub
    End If
    
    ' Look for first word document
    strDocName = Dir(strDir & "*.doc")
    
    ' If no word document found then exit
    If strDocName = "" Then
        MsgBox "No files found!", vbCritical
        Exit Sub
    End If
    
    
    On Error GoTo ErrorHandler
    ' Get open instance of word application if available
    Set WdApp = GetObject(, "Word.Application")
    
    
    Do While strDocName <> ""
    
        ' Open word document
        Set WdDoc = WdApp.Documents.Open(strDir & strDocName)
    
        With Sheets("Sheet1")
    
            ' Find last completed row on reporting log
            lngWriteRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
            
            ' Populate worksheet
            .Range("A" & lngWriteRow).Value = WdDoc.FormFields("Text1").Result
            .Range("B" & lngWriteRow).Value = WdDoc.FormFields("Text2").Result
            .Range("C" & lngWriteRow).Value = WdDoc.FormFields("Dropdown1").Result
            .Range("D" & lngWriteRow).Value = strDocName
            .Range("E" & lngWriteRow).Value = Now
        
        End With
    
        ' Close word document and move to Logged folder
        WdDoc.Close SaveChanges:=False
        Name strDir & strDocName As strDir & "Logged/" & strDocName
    
        ' Look for next word document
        strDocName = Dir
    
    Loop
    
    Set WdDoc = Nothing
    If blnAppOpen = False Then
        WdApp.Quit
        Set WdApp = Nothing
    End If
    
    Exit Sub
    
    ' Error Handler
    ErrorHandler:
    If Err.Number = 429 Then
    'Word is not running, open Word with CreateObject
    Set WdApp = CreateObject("Word.Application")
    blnAppOpen = False
    Resume Next
    Else
    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    End If
    
    End Sub

    You will need to set references to the Miscrosoft Forms and Microsoft Word object libraries in the Excel VBA editor.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    06-15-2011
    Location
    Norway
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Importing data from a Word 2010 form to Excel 2010.

    Hi,
    Thanks a lot. I will giver this a go as soon as possible.

    Best regards,
    mlang

  4. #4
    Registered User
    Join Date
    07-02-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Importing data from a Word 2010 form to Excel 2010.

    Hi Dom,
    Are there any updates to the file since you've originally posted it?
    Thanks,
    Tricia

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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