Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed from AZ - 22 Jan 2008 22:58 GMT
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
fumei - 23 Jan 2008 11:49 GMT
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.
>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
[quoted text clipped - 5 lines]
>
>Ed
Ed from AZ - 23 Jan 2008 13:44 GMT
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

> 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
[quoted text clipped - 3 lines]
>
> 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
[quoted text clipped - 39 lines]
> --
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/200801/1
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.