Originally Posted by
mattdafool
I will do more searching, sorry for wasting time.
It's not so much a matter of wasting time but pointing out that forums such as this typically have vast amounts of code, etc. that can point you in the right direction. Here's an Excel macro, based on the one in the link I posted, for handling your 'hard' question:
Sub GetFormData()
' Note: this code requires a reference to the Word object model,
' inserted via Tools|References in the Excel VBA Editor
Application.ScreenUpdating = False
Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim FmFld As Word.FormField
Dim strFolder As String, strFile As String
Dim WkSht As Worksheet, r As Long, c As Long
Const StrSrcFldr = "C:\Users\Matt\Complaints\UnRegistered QA Forms" 'Path to source folder
Const StrDstFldr = "C:\Users\Matt\Complaints\Registered QA Forms" 'Path to destination folder
Set WkSht = ActiveSheet
r = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(StrSrcFldr & "*.doc", vbNormal)
While strFile <> ""
r = r + 1
Set wdDoc = wdApp.Documents.Open(Filename:=StrSrcFldr & "\" & strFile, _
AddToRecentFiles:=False, Visible:=False)
With wdDoc
c = 0: .FormFields("CCRef").Result = WkSht.Cells(r - 1, 3) + 1
For Each FmFld In .FormFields
c = c + 1
WkSht.Cells(r, c) = FmFld.Result
MsgBox c & vbTab & FmFld.Result & vbCr & WkSht.Cells(r, c)
Next
.SaveAs2 Filename:=StrDstFldr & Split(.Name, ".doc")(0) & ".docx", _
FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
.Close SaveChanges:=False
End With
'Kill StrSrcFldr & "\" & strFile
strFile = Dir()
Wend
wdApp.Quit
'ActiveWorkbook.Save
Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
Application.ScreenUpdating = True
End Sub
As coded, the macro assumes your CCF references will be in column 3. That's just because your form's layout makes it easier to work with such an arrangement. Also, since I'm not sure what your CCF reference codes are comprised of, at this stage it's just a simple incremental counter. As mentioned in my previous reply, you'll need to add a text formfield to the document for the CCF reference. I've also left the file deletion code and workbook save code commented-out. That's so you can test the macro without the risk it will delete/save something in error. You will also need to supply the correct paths for the source and destination folders.
Note that the macro only collects data from formfields. Your form has a formfield checkbox for the 'QA Report Required' 'no' response, but a content control for the 'yes' response. Your form also has content control checkboxes for the 'Credit / Replacement Required' responses. You should use either formfields or content controls throughout your document. Using a mix of both can lead to problems, as they were not designed to work together. Personally, I'd be inclined to replace all those checkboxes with dropdown formfields - one for the 'QA Report Required' response and another for the 'Credit / Replacement Required' response - so the user can only make one choice (with out the need for a macro to force an exclusive choice via formfields).