Need help, please, moving text from one table range to another

E

Ed from AZ

I am trying to move the contents of a table in one document into the
cells of a larger table in a second document. The line
doc2.Range(Start:=tbl3.Cell(13, 1), End:=tbl3.Cell(18, 4)) =
tbl2.Range
gives me a "Type Mismatch" error.

How can I make this happen?

Ed
 
F

fumei via OfficeKB.com

First off, declaring a Range does indeed use a Start, and and End. However,
Start:=tbl3.Cell(13, 1) is NOT a valid value for a Range value. Thus: Type
Mis-match

Start:= needs to be a NUMBER

tbl3.Cell(13, 1) is NOT a number, it is a cell.

Second, I do not know what your other code is like, but I would guess that it
could probably run better using objects. This is a simple example. An
active document, and an already open (but NOT active) document named "Yadda".
The code makes a table object of the third table in the active document, and
a table object in the target document ("Yadda").

Dim ThisDoc As Document
Dim ThatDoc As Document
Dim SourceTable As Table
Dim TargetTable As Table

Set ThisDoc = ActiveDocument
Set ThatDoc = Documents("Yadda")
Set SourceTable = ThisDoc.Tables(3)
Set TargetTable = ThatDoc.Tables(2)

Now you can just transfer contents from one table to the other. You do not
have to make "Yadda" active; you do not have to copy and paste.

TargetTable.Cell(2, 2).Range.Text =
SourceTable.Cell(5,2).Range.Text

This makes Tables(2).Cell(2,2) in "Yadda" the contents of Tables(3).Cell(5,2)
in the active document.

This is a very simple example. You can also use cell objects and dump stuff
even mor eefficiently.

NOTE: you will need to strip off end-of-cell markers using the Range of the
cells, if you want a perfect copy.
 
E

Ed from AZ

Thanks for the reply. Thinking about it afterwards, I realized this
is probably the Excel VBA dialect, not Word! Oops!!

With your reply and a bit more thinking, it's working now.

Thanks again!

Ed
 

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