Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Merge cells in word 2003

Merge cells in word 2003

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Larza123
    wrote on last edited by
    #1

    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!

    G W 2 Replies Last reply
    0
    • L Larza123

      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!

      G Offline
      G Offline
      Goalie35
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • G 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

        L Offline
        L Offline
        Larza123
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • L Larza123

          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!

          W Offline
          W Offline
          wowo608
          wrote on last edited by
          #4

          worksheet is an item of excel. Word.Cell mergeBeginCell = wordTable.Cells(1, 2); Word.Cell mergeEndCell = wordTable.Cell(2, 2); mergeBeginCell.Merge(mergeEndCell);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups