assigning a value to a table cell using VBA in word

M

mark_jm

I am using vba code as code assigned to a button on a user form.
The offending code is


Dim mytable As Table

Set mytable = ActiveDocument.Tables(1)
MsgBox (mytable.Cell(1, 1))
id = student(numc, 2) ' where numc is
an integer used to select the sorrect table row
mytable.Columns(1).Cells(1) = id 'Student is an array holding
values read from the form

It falls over highlighting the code ".Cells(1)=" in blue stating error
message " invalid use of property".

The help at that point talks about property let and property get statements ?

I have also tried mytable.Cells(numc,1) and mytable.cells(1, 1) just to try
and get it working with no joy

Please help
 
T

Tony Jollans

Try using ...

mytable.Columns(1).Cells(1).Range = id

or, more explicitly, ...

mytable.Columns(1).Cells(1).Range.Text = id
 
M

mark_jm

Fantastic....thanks .............you dont know how long I've been messing
about with that

Regards

Mark

Tony said:
Try using ...

mytable.Columns(1).Cells(1).Range = id

or, more explicitly, ...

mytable.Columns(1).Cells(1).Range.Text = id

--
Enjoy,
Tony
I am using vba code as code assigned to a button on a user form.
The offending code is
[quoted text clipped - 17 lines]
Please help
 

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