Help- Error 91

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
 
H

Helmut Weber

Hi Mark,
ActiveDocument.FormFields("RLAddress" & scounter).Result =
ActiveSheet.Range("RLAddress" & scounter).Text
....

To Word Activesheet doesn't mean anything.
Try xl.activesheet instead.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top