If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Cloning a Cell
Hello:
I am making a word application that creates cards. I use a table with many cells. The first cell is the "Layout Cell". I want to be able to copy everything that is in the "Layout Cell" ( eg...pictures, text, font, and text formatting). I use this code and it seems to add extra cells to my table. I dont want it to add any cells at all. 'this copies the first cell which is the Layout Cell ThisDocument.Tables.Item(1).Cell(1, 1).Range.Copy() 'Loop threw all the cells For rowcount As Integer = 1 To IntRows For colcount As Integer = 1 To IntCols 'this looks to see if it is the first cell... if it is ...do nothing If Not (rowcount = 1 And colcount = 1) Then 'This pastes it ThisDocument.Tables.Item(1).Cell(rowcount, colcount).Range.Paste() End If Next Next This seems to copy the whole cell including the cell structure and adds another cell. I dont want to add any extra cells or the cells structures. I just want to copy the contents of the "Layout Cell" to all the other cells. Please........Pretty please....does anyone know how I can accomplish this???? Code samples are welcome Thanks in advance Brian |
#2
|
|||
|
|||
Cloning a Cell
Leaving aside the issue that the code you posted is chock-full of
syntax errors and couldn't possibly run as is, the problem you mention is due to copying the entire range of the layout cell, *including the cell marker*. When you paste that, of course you're going to get a new cell. The way around this is to assign the layout cell's range to a Range object and move the end of the Range object so it excludes the cell marker. You could copy and paste the content of this range, but it's more efficient simply to transfer the .FormattedText property of the range to each of the other cells. Here's code that actually runs: Sub ReplicateLayoutCell() Dim rowcount As Integer Dim colcount As Integer Dim MyRange As Range 'this points to the first cell which is the Layout Cell 'without the cell marker With ActiveDocument.Tables(1) Set MyRange = .Cell(1, 1).Range MyRange.MoveEnd Unit:=wdCharacter, Count:=-1 'Loop through all the cells For rowcount = 1 To .Rows.Count For colcount = 1 To .Columns.Count 'this looks to see if it is the first cell... 'if it is ...do nothing If Not (rowcount = 1 And colcount = 1) Then 'This replicates it .Cell(rowcount, colcount).Range.FormattedText = _ MyRange.FormattedText End If Next Next End With End Sub "theDutchie" wrote: Hello: I am making a word application that creates cards. I use a table with many cells. The first cell is the "Layout Cell". I want to be able to copy everything that is in the "Layout Cell" ( eg...pictures, text, font, and text formatting). I use this code and it seems to add extra cells to my table. I dont want it to add any cells at all. 'this copies the first cell which is the Layout Cell ThisDocument.Tables.Item(1).Cell(1, 1).Range.Copy() 'Loop threw all the cells For rowcount As Integer = 1 To IntRows For colcount As Integer = 1 To IntCols 'this looks to see if it is the first cell... if it is ...do nothing If Not (rowcount = 1 And colcount = 1) Then 'This pastes it ThisDocument.Tables.Item(1).Cell(rowcount, colcount).Range.Paste() End If Next Next This seems to copy the whole cell including the cell structure and adds another cell. I dont want to add any extra cells or the cells structures. I just want to copy the contents of the "Layout Cell" to all the other cells. Please........Pretty please....does anyone know how I can accomplish this???? Code samples are welcome Thanks in advance Brian -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://www.mvps.org/word |
#3
|
|||
|
|||
Cloning a Cell
Jay:
Thanks for all your help. It is much appreciated. I thought that there was some sort of cell character somewhere....but I couldnt figure how to stop it from replicating. Thanks again Brian |
Thread Tools | |
Display Modes | |
|
|