Thanks for fixing up my tags, Dreamboat!
I didn't even know that such a thing existed. And yes, weird thing about the word "result" being spaced out.
I am trying all sorts of combinations here... I just can't figure out how to return the value of a bookmark. Arghhh!
This is so depressing!!
I am going to paste the whole function using those tags... Let's see how it looks..
Private Function FillExcel(strFile As String, intFileNum As Integer)
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Dim x As Integer
On Error Resume Next
Set WordDoc = WordObj.Documents.Open(strFile)
' Uncomment the ' on the next line to see Word cycle through the values
WordObj.Visible = True
' Activate the current WorkSheet (Change Sheet1 to whatever Worksheet you are using)
Worksheets("Sheet1").Activate
' Prompt to use FieldNames as Column Headers
If intFileNum = 1 Then
If MsgBox("In the first row, would you like to paste the headers (instead of a blank line)?", _
vbYesNo, "Column Headers") = vbYes Then
For x = 1 To WordDoc.Bookmarks.Count
' This line takes the name of the bookmark and puts it
' on the first row (only for the first doc opened)
ActiveSheet.Cells(intRow, x + intCol - 1) = WordDoc.Bookmarks(x).Name
' This line works like a charm. I see all the bookmarks in the document.
Next
End If
End If
' Loop through all the fields
For x = 1 To WordDoc.Bookmarks.Count
' intRow is the file order number (each file will import on a new row)
' the x is the column - Essentially it'll cycle through all the bookmarks in the Word doc
ActiveSheet.Cells(intRow + intFileNum, x + intCol - 1) = _
WordDoc.FormFields(WordDoc.Bookmarks(x).Name).Result
' This is the problematic line. I want all the bookmark values,
' not just the ones that are formfields...
Next
WordDoc.Close
Set WordDoc = Nothing
End Function
<< Hey these tags are cool! >>