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 / April 2006

Tip: Looking for answers? Try searching our database.

Replace a word table by an excel table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex St-Pierre - 05 Apr 2006 13:22 GMT
Hi,
I have a table in Word and I replace it by a range table in excel. Excel
range ("table1_1") should go to replace the table in bookmark("table1_1"), ...
I use the following codification but the table #2 and #3 are copied inside
word table #1 (last cell) ?? When I delete the second table, it's like if the
cursur is going to table #1. Is there a way to use a replace table instead of
using delete and copy-paste function ?
Thanks !
Signature

Alex St-Pierre

   For nbTab = 1 To 3

   If nbTab = 1 Then
   Set rngExcel = wbExcel.Application.sheets("table1.1").Range("table1_1")
   Set rng = docWord1.Bookmarks("Table1_1").Range
   ElseIf nbTab = 2 Then
   Set rngExcel = wbExcel.Application.sheets("table1.2").Range("table1_2")
   Set rng = docWord1.Bookmarks("Table1_2").Range
   ElseIf nbTab = 3 Then
   Set rngExcel = wbExcel.Application.sheets("table1.3").Range("table1_3")
   Set rng = docWord1.Bookmarks("Table1_3").Range
   End If

   Set tbl = rng.Tables(1)
   tbl.Delete
   rngExcel.Copy
   Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,
RTF:=True
   Set tbl = rng.Tables(1)
   ...
   Next nbTab

Ed - 05 Apr 2006 18:57 GMT
Hi, Alex.  I'm not an expert by any means, but let me make a suggestion:
Try replacing Selection in
   Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,
with tbl.Range to give
   tbl.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,

"Range" returns an area independent of the insertion point / cursor
position.  "Selection" returns the exact insertion point, regardless of any
range you have referenced in your code.  If your insertion point is in a
table cell, then Selection will paste everything there, and ignore any
referenced range.

HTH
Ed

> Hi,
> I have a table in Word and I replace it by a range table in excel. Excel
[quoted text clipped - 7 lines]
> using delete and copy-paste function ?
> Thanks !
Alex St-Pierre - 09 Apr 2006 20:32 GMT
I tried this but the newtable is always added to the old table
Set tbl = rng.Tables(1)
   rngExcel.Copy
   tbl.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,
RTF:=True
   Set tbl = rng.Tables(1)

This works:
Set tbl = rng.Tables(1)
   rngExcel.Copy
   tbl.select
   selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,
RTF:=True
--
Alex St-Pierre

"Ed" a écrit :

> Hi, Alex.  I'm not an expert by any means, but let me make a suggestion:
> Try replacing Selection in
[quoted text clipped - 22 lines]
> > using delete and copy-paste function ?
> > Thanks !
 
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.