Hello,
I'm running into a VBA error: Compile Error: Method or Data Member not found. I'm trying to run my code which copies data from Excel and pastes it into Word FormFields. The error occurs on this line of code
and it specifically highlights
My entire code is:
Any ideas why this is occurs? Thanks!
I'm running into a VBA error: Compile Error: Method or Data Member not found. I'm trying to run my code which copies data from Excel and pastes it into Word FormFields. The error occurs on this line of code
VBA Code:
For r = 3 To xlSht.Range("A" & .Rows.Count).End(xlUp).Row
and it specifically highlights
Rich (BB code):
.Rows.
My entire code is:
Code:
Sub CC()
Dim wdApp As New Word.Application, wdDoc As Word.Document, wdRng As Word.Range
Dim xlSht As Worksheet, r As Long, c As Long
Set xlSht = ThisWorkbook.Sheets("Sheet1")
With wdApp
.Visible = True
For r = 3 To xlSht.Range("A" & .Rows.Count).End(xlUp).Row
If xlSht.Range("A" & r).EntireRow.Hidden = False Then
Set wdDoc = wdApp.Documents.Add(Template:="X:\abcde.docx")
With wdDoc
For c = 1 To 4
If .Bookmarks("Text" & c).Exists Then
.Bookmarks("Text" & c).Range.Fields(1).Result.Text = xlSht.Cells(r, c).Text
Else
MsgBox "Form field bookmark 'Text" & c & "' doesn't exist in:" & vbCr & _
.AttachedTemplate.FullName
End If
Next
.SaveAs2 Filename:="X:\abcde.docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
.Close
End With
End If
Next r
.Quit
End With
End Sub
Any ideas why this is occurs? Thanks!