mikeannetta
New Member
- Joined
- Oct 6, 2015
- Messages
- 13
- Office Version
- 2019
- Platform
- Windows
I see some old post to this for table data, but not form data.
I also have tried some of the internet solutions, the "closest solution" I saw for macro to do what I wanted was as follows, and for some unknown reason to me , its not working?
Error message is "Run-time Error '438': Object doesn't support this property or method.
It stops around Bolded / RED Texted area where it should pickup and open a word docx file? Anybody have an idea how to fix? I'll have about a 100 forms to get data from.....
Sub MM1GetFormData()
Application.ScreenUpdating = False
Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim FrFld As Word.FormField
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
'MAY NEED TO FIX FILE TYPE FROM DOCX to ???
strfile = Dir(StrFolder & "\*.docx", vbNormal)
While strfile <> ""
i = 1 + i
Set wdDoc = wdApp.Documents.Open(Filename:=StrFolder & "" & strfile, Addtorecentfiles:=False, Visible:=False)
With wdDoc
j = 0
For Each FmFld In .FormFields
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 = False
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.Item.Path
Set oFolder = Nothing
End Function
I also have tried some of the internet solutions, the "closest solution" I saw for macro to do what I wanted was as follows, and for some unknown reason to me , its not working?
Error message is "Run-time Error '438': Object doesn't support this property or method.
It stops around Bolded / RED Texted area where it should pickup and open a word docx file? Anybody have an idea how to fix? I'll have about a 100 forms to get data from.....
Sub MM1GetFormData()
Application.ScreenUpdating = False
Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim FrFld As Word.FormField
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
'MAY NEED TO FIX FILE TYPE FROM DOCX to ???
strfile = Dir(StrFolder & "\*.docx", vbNormal)
While strfile <> ""
i = 1 + i
Set wdDoc = wdApp.Documents.Open(Filename:=StrFolder & "" & strfile, Addtorecentfiles:=False, Visible:=False)
With wdDoc
j = 0
For Each FmFld In .FormFields
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 = False
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.Item.Path
Set oFolder = Nothing
End Function