Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2014, 07:39 AM
AaaTeX AaaTeX is offline Using VB.Net 2010 I cannot duplicate tables in the correct place Windows 7 64bit Using VB.Net 2010 I cannot duplicate tables in the correct place Office 2013
Novice
Using VB.Net 2010 I cannot duplicate tables in the correct place
 
Join Date: Jul 2014
Posts: 8
AaaTeX is on a distinguished road
Default Using VB.Net 2010 I cannot duplicate tables in the correct place

I am working on a VB.Net 2010 program using the Interop class.



We are having problems trying to duplicate a table more than 1 time to be put in the place we want.

It is either merging it with the original table in the Word Doc or putting it into the next table.

Is there a clean explanation on how a table can be duplicated 2-3 times?

We are currently using functions as:
WordApp.Selection.InsertAfter(MySepStr) ' not then it appends to the DevTable
WordApp.Selection.MoveDown() ' Move down needed if not appends to origina table
WordApp.Selection.Paste()
' Manual paste works without the move down this does not. It puts it in the next table
Reply With Quote
  #2  
Old 08-01-2014, 05:26 PM
macropod's Avatar
macropod macropod is offline Using VB.Net 2010 I cannot duplicate tables in the correct place Windows 7 32bit Using VB.Net 2010 I cannot duplicate tables in the correct place Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There are numerous ways of doing this. For example, in VBA:
Code:
Sub Demo()
Dim Rng As Range
With ActiveDocument
  Set Rng = .Tables(1).Range
  Rng.Collapse wdCollapseEnd
  Rng.FormattedText = .Tables(1).Range.FormattedText
End With
End Sub
or:
Code:
Sub Demo()
Dim Rng As Range
With ActiveDocument
  Set Rng = .Tables(1).Range
  Rng.Copy
  Rng.Collapse wdCollapseEnd
  Rng.Paste
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-03-2014, 06:30 AM
AaaTeX AaaTeX is offline Using VB.Net 2010 I cannot duplicate tables in the correct place Windows 7 64bit Using VB.Net 2010 I cannot duplicate tables in the correct place Office 2013
Novice
Using VB.Net 2010 I cannot duplicate tables in the correct place
 
Join Date: Jul 2014
Posts: 8
AaaTeX is on a distinguished road
Default Not Working as expected

I implemented the code but it is still appending the table to the previous table. So Extending it not creating a brand new table which is what I want to do.

We are using VB.Net 2010 not VBA/VB6. So we are doing
MyCopyFromRange = pCopyFromTable.Range ' pCopyFromTable is a parameter on the routine

MyCopyFromRange
.Copy

MyCopyFromRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)

MyCopyFromRange.Paste

What does Collapse do?
The previous technique I used worked on the first copy but not the second. (In the case I am working on it is trying to clone 2 tables).
Reply With Quote
  #4  
Old 08-03-2014, 07:00 PM
macropod's Avatar
macropod macropod is offline Using VB.Net 2010 I cannot duplicate tables in the correct place Windows 7 32bit Using VB.Net 2010 I cannot duplicate tables in the correct place Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Collapse, as its name suggests, collapses the range to either end - you can use wdCollapseStart or wdCollapseEnd.

Your previous post indicated the tables were being merged, which implied to me that one was being inserted into the other. What the code I posted does is to append the tables. If you want to insert the replicated content as a new table, you need to have an empty paragraph between them, which you could create with something like:
Code:
Sub Demo()
Dim Rng As Range
With ActiveDocument
  Set Rng = .Tables(1).Range
  Rng.Collapse wdCollapseEnd
  Rng.FormattedText = .Tables(1).Range.FormattedText
  Rng.Tables(1).Split Rng.Rows(1)
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
.net, table

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VB.Net 2010 I cannot duplicate tables in the correct place editing a number/text at one place and changes taking place wherever it appears anurag.butoliya Word 1 06-14-2014 06:27 PM
Using VB.Net 2010 I cannot duplicate tables in the correct place How to tell Word (2010) my Capitalization is correct JRW1015 Word 3 08-13-2013 04:57 PM
Using VB.Net 2010 I cannot duplicate tables in the correct place Word 2007 Tables - Shift cells backwards one place bloodge1 Word Tables 3 08-28-2012 10:11 PM
Outlook 2010 duplicate email folders randolsgm1 Outlook 1 07-19-2011 05:48 PM
Using VB.Net 2010 I cannot duplicate tables in the correct place Duplicate holidays in Outlook 2010 pln@dlf.org Outlook 1 06-06-2011 11:45 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft