M
Mark L
I'm hoping someone can help me with this because I am pulling my hair out
over this! I am using a sub to copy data from an XL sheet into a Word doc.
The sub is shown below. When I run it, I get an Error 91- Object variable or
With block variable not set. (the error highlights the line starting with
ActiveDocument.FormFields("RLAddress........What's frustrating is that I use
the exact same structure to copy other cells from the sheet in another sub
and it works fine without any error message. I made sure I wasn't re-using
any variable names, but I can't figure this one out. I am still a novice at
this, so if you can help me I would be very grateful. Here's the sub:
Sub AddTableInfo()
Dim xl As Excel.Application
Dim scounter As Integer
Dim xTable As Table
Set xl = GetObject(, "Excel.Application")
xl.Workbooks.Open ("C:\Documents and Settings\02774\Application
Data\Microsoft\Templates\firsttest3.xls")
Set xTable = ActiveDocument.Tables(5)
For scounter = 2 To xTable.Rows.Count
ActiveDocument.FormFields("RLAddress" & scounter).Result =
ActiveSheet.Range("RLAddress" & scounter).Text
If ActiveSheet.Range("RLSite" & scounter) = "1" Then
ActiveDocument.FormFields("RLSite" & scounter).CheckBox.Value = True
End If
Next scounter
xl.Quit
End Sub
over this! I am using a sub to copy data from an XL sheet into a Word doc.
The sub is shown below. When I run it, I get an Error 91- Object variable or
With block variable not set. (the error highlights the line starting with
ActiveDocument.FormFields("RLAddress........What's frustrating is that I use
the exact same structure to copy other cells from the sheet in another sub
and it works fine without any error message. I made sure I wasn't re-using
any variable names, but I can't figure this one out. I am still a novice at
this, so if you can help me I would be very grateful. Here's the sub:
Sub AddTableInfo()
Dim xl As Excel.Application
Dim scounter As Integer
Dim xTable As Table
Set xl = GetObject(, "Excel.Application")
xl.Workbooks.Open ("C:\Documents and Settings\02774\Application
Data\Microsoft\Templates\firsttest3.xls")
Set xTable = ActiveDocument.Tables(5)
For scounter = 2 To xTable.Rows.Count
ActiveDocument.FormFields("RLAddress" & scounter).Result =
ActiveSheet.Range("RLAddress" & scounter).Text
If ActiveSheet.Range("RLSite" & scounter) = "1" Then
ActiveDocument.FormFields("RLSite" & scounter).CheckBox.Value = True
End If
Next scounter
xl.Quit
End Sub