Merge cells in word 2003
-
I want to merge cells in a table in word 2003 from visual studio 2005 C#. I manage to merge cells once in a table but when I try to merge other cells in the same table I get an error that says that the rows is not accessable because som cells have been merged. This is the way I do it. Word.Range range = MyWordApplication.Selection.Range; range.Start = wordTable.Rows.Item(1).Cells.Item(2).Range.Start; range.End = wordTable.Rows.Item(2).Cells.Item(2).Range.End; range.Cells.Merge(); When I try it once more with other cells I get an error. Does anyone have any Idea how I can get this to work? Is there another way to select cells and then merge them? I think that my way maybe selects all cells from row 1 column 2 to row 2 column 2 but I only want to select these two cells. If you have any idea please let me know. Thanks!
-
I want to merge cells in a table in word 2003 from visual studio 2005 C#. I manage to merge cells once in a table but when I try to merge other cells in the same table I get an error that says that the rows is not accessable because som cells have been merged. This is the way I do it. Word.Range range = MyWordApplication.Selection.Range; range.Start = wordTable.Rows.Item(1).Cells.Item(2).Range.Start; range.End = wordTable.Rows.Item(2).Cells.Item(2).Range.End; range.Cells.Merge(); When I try it once more with other cells I get an error. Does anyone have any Idea how I can get this to work? Is there another way to select cells and then merge them? I think that my way maybe selects all cells from row 1 column 2 to row 2 column 2 but I only want to select these two cells. If you have any idea please let me know. Thanks!
Hi Larza. To answer what I'm assuming you already know, yes, you're not specifying your range properly. When you try to merge a 2nd time, you're re-merging cells that are already merged. I set my range a little differently. I have 1 line of code that specifies the 2 specific cells I wish to work with(and every cell within their range). Try using it and see if it helps. range = Worksheet.get_Range(Worksheet.Cells[1, 1], Worksheet.Cells[1, 2]); range.Merge(true); This code never gives me a problem. Try it and see if it helps. -Goalie35
-
Hi Larza. To answer what I'm assuming you already know, yes, you're not specifying your range properly. When you try to merge a 2nd time, you're re-merging cells that are already merged. I set my range a little differently. I have 1 line of code that specifies the 2 specific cells I wish to work with(and every cell within their range). Try using it and see if it helps. range = Worksheet.get_Range(Worksheet.Cells[1, 1], Worksheet.Cells[1, 2]); range.Merge(true); This code never gives me a problem. Try it and see if it helps. -Goalie35
Hi! sorry for my late reply. Thanx for your help but I have a few questions. What type is the Worksheet? I have an object of type Word.ApplicationClass. But I can't find the worksheet. Won't your range be from the first cell to your last cell? I mean if you write it like this: range = Worksheet.get_Range(Worksheet.Cells[1, 1], Worksheet.Cells[2, 2]); Will the range then only contain 2 cells or every cell between the cells? Thanx!
-
I want to merge cells in a table in word 2003 from visual studio 2005 C#. I manage to merge cells once in a table but when I try to merge other cells in the same table I get an error that says that the rows is not accessable because som cells have been merged. This is the way I do it. Word.Range range = MyWordApplication.Selection.Range; range.Start = wordTable.Rows.Item(1).Cells.Item(2).Range.Start; range.End = wordTable.Rows.Item(2).Cells.Item(2).Range.End; range.Cells.Merge(); When I try it once more with other cells I get an error. Does anyone have any Idea how I can get this to work? Is there another way to select cells and then merge them? I think that my way maybe selects all cells from row 1 column 2 to row 2 column 2 but I only want to select these two cells. If you have any idea please let me know. Thanks!