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)
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]
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