Consulting

Results 1 to 10 of 10

Thread: Horizontally merged cells

  1. #1
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    226
    Location

    Horizontally merged cells

    Guys I have searched high and low and cannot find any information on unmerging horizontally merged cells in a word table. Unmerging vertically works can unmerging horizontally?

    Unmerging vertically link:
    http://www.vbaexpress.com/forum/show...y-merged-cells

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,671
    Location
    You need to understand that, depsite what appears to work in your other thread, Word cannot tell whether a cell has been merged with another cell or whether what appears to be a merged cell is the result of other cells being split - vertically and/or horizontally.

    All the code you're now using does is to assume any differences in vertical heights are due to vertical merges; the possibility of the vertical splitting of adjoining cells isn't even considered.

    For potential horizontal splits/merges, things are even more complicated, as the cells in a given column can have different widths without any splitting or merging being a factor.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    226
    Location
    Thanks for the reply

    Quote Originally Posted by macropod View Post
    For potential horizontal splits/merges, things are even more complicated, as the cells in a given column can have different widths without any splitting or merging being a factor.
    so since my table has exact column widths:
     With oTbl
    .Columns(1).SetWidth ColumnWidth:=60, _
    RulerStyle:=wdAdjustFirstColumn
    .Columns(2).SetWidth ColumnWidth:=200, _
    RulerStyle:=wdAdjustFirstColumn
    .Columns(3).SetWidth ColumnWidth:=200, _
    RulerStyle:=wdAdjustFirstColumn
    .Columns(4).SetWidth ColumnWidth:=60, _
    
    RulerStyle:=wdAdjustFirstColumn
    It may possible?

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,671
    Location
    So, if all the columns have pre-set widths, how can any of the cells be merged or split? Code such as you posted would not work on a table with horizontally merged/split cells.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    226
    Location
    That is the code that creates the table. it cannot be used to reset the column widths after any cells are merged. I was just showing you that the columns should have a specific width. I was thinking...is it possible to split a cell that is the width of a combination of 2, 3, or 4 cells based on the above widths? so if a cell ColumnWidth:=260 or 400 or 460 or 520 then split? so if it was 260 or 400 split in two if its 460 split in three if its 520 split in 4? Just a thought.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,671
    Location
    Consider the case where the user drags the right border of a cell in your 2nd column 60pt to the right. It's now 260pt wide, but nothing's been split or merged. Moreover, the corresponding cell in the 3rd column is now only 140pt wide. If such a scenario is possible, you might use:
    oTbl.Columns.DistributeWidth
    before resetting their widths. Other than that, you'd need to loop though all cells, finding which rows have fewer than 4 cells, then choosing one (or more) to split before using Columns.DistributeWidth, etc.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  7. #7
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    226
    Location
    Paul thanks for the discussion. I think I have a starting point. I will post when I get started.

  8. #8
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    226
    Location
    I just had a forced Microsoft update and lost all macros for the last 3 months. If I bother to replace them. I'll reopen the thread and post results. What a disappointment. Second time this has happened.

  9. #9
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,671
    Location
    That suggests you're working in a corporate environment and your IT department kindly overwrote your Normal.dotm file - in which you were storing your macros. Next time, store them in a different template and keep a backup.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  10. #10
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    226
    Location
    Thanks for the advice. I think you said the same thing last time. LOL. IT guy here is a knob. He can't stand that I write macros. He says it's his job but the stuff I'm doing is above his knowledge.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •