Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 4 Jun 2008 14:37:37 -0400,    group: microsoft.public.word.tables        back       


Borders and Shading   
I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there. 

If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once.  I was wondering if there might be an easier way to do this? 

-- 

Regards
Michael Koerner
date: Wed, 4 Jun 2008 14:37:37 -0400   author:   Michael Koerner

Re: Borders and Shading   
Forgot to add I'm using Office 2007 running under XP

-- 

Regards
Michael Koerner


  "Michael Koerner"  wrote in message news:O4mMSJnxIHA.5832@TK2MSFTNGP02.phx.gbl...
  I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there. 

  If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once.  I was wondering if there might be an easier way to do this? 

  -- 

  Regards
  Michael Koerner
date: Wed, 4 Jun 2008 14:48:41 -0400   author:   Michael Koerner

Re: Borders and Shading   
It might be better to modify the macro so that it splits the table before the row that is added so that the application of the border to that row will have no impact on the previous row.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

  "Michael Koerner"  wrote in message news:O4mMSJnxIHA.5832@TK2MSFTNGP02.phx.gbl...
  I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there. 

  If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once.  I was wondering if there might be an easier way to do this? 

  -- 

  Regards
  Michael Koerner
date: Thu, 5 Jun 2008 19:22:01 +1000   author:   Doug Robbins - Word MVP

Re: Borders and Shading   
Doug;

I thought of that. but my knowledge of macro programming is limited to the spelling of the word macro <g> Below is the code for the macro that someone provided for me awhile back. If you or anyone can change the code to do this, it would be greatly appreciated. Might be useful to others also.

Sub InsertFramedHeadRow()
' insert a framed header row into the table
Dim i As Long, j As Long
Dim Init As String
Dim newrow As Row
Dim initrng As Range
Dim dtable As Table
Set dtable = Selection.Tables(1)
j = dtable.Rows.Count
Init = dtable.Cell(j, 1).Range.Characters(1)
For i = j To 1 Step -1
    Set initrng = dtable.Cell(i, 1).Range
    If initrng.Characters(1) <> Init Then
        Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
        With newrow
            .Cells.Merge
            .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Range.Text = "- " & Init & " -"
            .Range.Font.Bold = True
            .Range.Shading _
                .BackgroundPatternColor = wdColorGray10
                .Height = InchesToPoints(0.24)
                .Borders.Enable = wdLineStyleSingle
                .Borders.OutsideLineWidth = wdLineWidth100pt
        End With
        Init = initrng.Characters(1)
    End If
Next i
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
With newrow
    .Cells.Merge
    .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Range.Text = Init
    .Range.Font.Bold = True
    .Range.Shading.BackgroundPatternColor = wdColorGray10
End With
End Sub



-- 

Regards
Michael Koerner


  "Doug Robbins - Word MVP"  wrote in message news:O8$cf2uxIHA.2064@TK2MSFTNGP05.phx.gbl...
  It might be better to modify the macro so that it splits the table before the row that is added so that the application of the border to that row will have no impact on the previous row.

  -- 
  Hope this helps.

  Please reply to the newsgroup unless you wish to avail yourself of my
  services on a paid consulting basis.

  Doug Robbins - Word MVP

    "Michael Koerner"  wrote in message news:O4mMSJnxIHA.5832@TK2MSFTNGP02.phx.gbl...
    I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there. 

    If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once.  I was wondering if there might be an easier way to do this? 

    -- 

    Regards
    Michael Koerner
date: Thu, 5 Jun 2008 06:30:20 -0400   author:   Michael Koerner

Re: Borders and Shading   
Try

Sub InsertFramedHeadRow()
' insert a framed header row into the table
Dim i As Long, j As Long
Dim Init As String
Dim newrow As Row
Dim initrng As Range
Dim dtable As Table
Set dtable = Selection.Tables(1)
j = dtable.Rows.Count
Init = dtable.Cell(j, 1).Range.Characters(1)
For i = j To 1 Step -1
    Set initrng = dtable.Cell(i, 1).Range
    If initrng.Characters(1) <> Init Then
        Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
        dtable.Split (newrow)
        With newrow
            .Cells.Merge
            .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Range.Text = "- " & Init & " -"
            .Range.Font.Bold = True
            .Range.Shading _
                .BackgroundPatternColor = wdColorGray10
                .Height = InchesToPoints(0.24)
                .Borders.Enable = wdLineStyleSingle
                .Borders.OutsideLineWidth = wdLineWidth100pt
        End With
        Init = initrng.Characters(1)
    End If
Next i
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
With newrow
    .Cells.Merge
    .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Range.Text = Init
    .Range.Font.Bold = True
    .Range.Shading.BackgroundPatternColor = wdColorGray10
End With
End Sub

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

  "Michael Koerner"  wrote in message news:OJNrrcvxIHA.4952@TK2MSFTNGP05.phx.gbl...
  Doug;

  I thought of that. but my knowledge of macro programming is limited to the spelling of the word macro <g> Below is the code for the macro that someone provided for me awhile back. If you or anyone can change the code to do this, it would be greatly appreciated. Might be useful to others also.

  Sub InsertFramedHeadRow()
  ' insert a framed header row into the table
  Dim i As Long, j As Long
  Dim Init As String
  Dim newrow As Row
  Dim initrng As Range
  Dim dtable As Table
  Set dtable = Selection.Tables(1)
  j = dtable.Rows.Count
  Init = dtable.Cell(j, 1).Range.Characters(1)
  For i = j To 1 Step -1
      Set initrng = dtable.Cell(i, 1).Range
      If initrng.Characters(1) <> Init Then
          Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
          With newrow
              .Cells.Merge
              .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
              .Range.Text = "- " & Init & " -"
              .Range.Font.Bold = True
              .Range.Shading _
                  .BackgroundPatternColor = wdColorGray10
                  .Height = InchesToPoints(0.24)
                  .Borders.Enable = wdLineStyleSingle
                  .Borders.OutsideLineWidth = wdLineWidth100pt
          End With
          Init = initrng.Characters(1)
      End If
  Next i
  Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
  With newrow
      .Cells.Merge
      .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Range.Text = Init
      .Range.Font.Bold = True
      .Range.Shading.BackgroundPatternColor = wdColorGray10
  End With
  End Sub



  -- 

  Regards
  Michael Koerner


    "Doug Robbins - Word MVP"  wrote in message news:O8$cf2uxIHA.2064@TK2MSFTNGP05.phx.gbl...
    It might be better to modify the macro so that it splits the table before the row that is added so that the application of the border to that row will have no impact on the previous row.

    -- 
    Hope this helps.

    Please reply to the newsgroup unless you wish to avail yourself of my
    services on a paid consulting basis.

    Doug Robbins - Word MVP

      "Michael Koerner"  wrote in message news:O4mMSJnxIHA.5832@TK2MSFTNGP02.phx.gbl...
      I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there. 

      If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once.  I was wondering if there might be an easier way to do this? 

      -- 

      Regards
      Michael Koerner
date: Fri, 6 Jun 2008 22:02:02 +1000   author:   Doug Robbins - Word MVP

Re: Borders and Shading   
Doug; thanks for taking the time. Greatly appreciated. The macro gives me a Run-time error '5': Invalid procedure call,and when I click on debug the following line is highlighted. 

If initrng.Characters(1) <> Init Then
        Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
        dtable.Split (newrow)
        With newrow

-- 

Regards
Michael Koerner


  "Doug Robbins - Word MVP"  wrote in message news:%23k9ol08xIHA.2384@TK2MSFTNGP02.phx.gbl...
  Try

  Sub InsertFramedHeadRow()
  ' insert a framed header row into the table
  Dim i As Long, j As Long
  Dim Init As String
  Dim newrow As Row
  Dim initrng As Range
  Dim dtable As Table
  Set dtable = Selection.Tables(1)
  j = dtable.Rows.Count
  Init = dtable.Cell(j, 1).Range.Characters(1)
  For i = j To 1 Step -1
      Set initrng = dtable.Cell(i, 1).Range
      If initrng.Characters(1) <> Init Then
          Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
          dtable.Split (newrow)
          With newrow
              .Cells.Merge
              .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
              .Range.Text = "- " & Init & " -"
              .Range.Font.Bold = True
              .Range.Shading _
                  .BackgroundPatternColor = wdColorGray10
                  .Height = InchesToPoints(0.24)
                  .Borders.Enable = wdLineStyleSingle
                  .Borders.OutsideLineWidth = wdLineWidth100pt
          End With
          Init = initrng.Characters(1)
      End If
  Next i
  Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
  With newrow
      .Cells.Merge
      .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Range.Text = Init
      .Range.Font.Bold = True
      .Range.Shading.BackgroundPatternColor = wdColorGray10
  End With
  End Sub

  -- 
  Hope this helps.

  Please reply to the newsgroup unless you wish to avail yourself of my
  services on a paid consulting basis.

  Doug Robbins - Word MVP

    "Michael Koerner"  wrote in message news:OJNrrcvxIHA.4952@TK2MSFTNGP05.phx.gbl...
    Doug;

    I thought of that. but my knowledge of macro programming is limited to the spelling of the word macro <g> Below is the code for the macro that someone provided for me awhile back. If you or anyone can change the code to do this, it would be greatly appreciated. Might be useful to others also.

    Sub InsertFramedHeadRow()
    ' insert a framed header row into the table
    Dim i As Long, j As Long
    Dim Init As String
    Dim newrow As Row
    Dim initrng As Range
    Dim dtable As Table
    Set dtable = Selection.Tables(1)
    j = dtable.Rows.Count
    Init = dtable.Cell(j, 1).Range.Characters(1)
    For i = j To 1 Step -1
        Set initrng = dtable.Cell(i, 1).Range
        If initrng.Characters(1) <> Init Then
            Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
            With newrow
                .Cells.Merge
                .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                .Range.Text = "- " & Init & " -"
                .Range.Font.Bold = True
                .Range.Shading _
                    .BackgroundPatternColor = wdColorGray10
                    .Height = InchesToPoints(0.24)
                    .Borders.Enable = wdLineStyleSingle
                    .Borders.OutsideLineWidth = wdLineWidth100pt
            End With
            Init = initrng.Characters(1)
        End If
    Next i
    Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
    With newrow
        .Cells.Merge
        .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Range.Text = Init
        .Range.Font.Bold = True
        .Range.Shading.BackgroundPatternColor = wdColorGray10
    End With
    End Sub



    -- 

    Regards
    Michael Koerner


      "Doug Robbins - Word MVP"  wrote in message news:O8$cf2uxIHA.2064@TK2MSFTNGP05.phx.gbl...
      It might be better to modify the macro so that it splits the table before the row that is added so that the application of the border to that row will have no impact on the previous row.

      -- 
      Hope this helps.

      Please reply to the newsgroup unless you wish to avail yourself of my
      services on a paid consulting basis.

      Doug Robbins - Word MVP

        "Michael Koerner"  wrote in message news:O4mMSJnxIHA.5832@TK2MSFTNGP02.phx.gbl...
        I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there. 

        If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once.  I was wondering if there might be an easier way to do this? 

        -- 

        Regards
        Michael Koerner
date: Fri, 6 Jun 2008 09:37:50 -0400   author:   Michael Koerner

Re: Borders and Shading   
Michael Koerner wrote:
> Doug; thanks for taking the time. Greatly appreciated. The macro
> gives me a Run-time error '5': Invalid procedure call,and when I
> click on debug the following line is highlighted.
>
> If initrng.Characters(1) <> Init Then
>         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i + 1))
>         dtable.Split (newrow)
>         With newrow

Very interesting behavior...

When you call a method and you don't use its return value (that is, you use 
it as a subroutine and not as a function), VBA prefers that you don't 
enclose the argument in parentheses and in some cases considers it an error 
(http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

So changing the Split call to

    dtable.Split BeforeRow:=newrow

or just

   dtable.Split newrow

will work without errors.

According to the Help topic on the Split method, the argument can be either 
a Row object (which newrow is) or the row number. That means you could write 
the line as

    dtable.Split BeforeRow:=newrow.Index

or just

   dtable.Split newrow.Index

But now comes the odd part. You can write the line as

   dtable.Split (newrow.Index)

and the macro will still work without errors, even though the parentheses 
are "wrong". But this line gets a compiler error:

   dtable.Split (BeforeRow:=newrow.Index)

-- 
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
all may benefit.
date: Fri, 6 Jun 2008 11:02:27 -0400   author:   Jay Freedman

Re: Borders and Shading   
Using this line

dtable.Split BeforeRow:=newrow 

seems to work okay. Now how does one go about removing all thw whitespace between the tables?

-- 

Regards
Michael Koerner


  "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
  Michael Koerner wrote:
  > Doug; thanks for taking the time. Greatly appreciated. The macro
  > gives me a Run-time error '5': Invalid procedure call,and when I
  > click on debug the following line is highlighted.
  >
  > If initrng.Characters(1) <> Init Then
  >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
  >         dtable.Split (newrow)
  >         With newrow

  Very interesting behavior...

  When you call a method and you don't use its return value (that is, you use 
  it as a subroutine and not as a function), VBA prefers that you don't 
  enclose the argument in parentheses and in some cases considers it an error 
  (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

  So changing the Split call to

      dtable.Split BeforeRow:=newrow

  or just

     dtable.Split newrow

  will work without errors.

  According to the Help topic on the Split method, the argument can be either 
  a Row object (which newrow is) or the row number. That means you could write 
  the line as

      dtable.Split BeforeRow:=newrow.Index

  or just

     dtable.Split newrow.Index

  But now comes the odd part. You can write the line as

     dtable.Split (newrow.Index)

  and the macro will still work without errors, even though the parentheses 
  are "wrong". But this line gets a compiler error:

     dtable.Split (BeforeRow:=newrow.Index)

  -- 
  Regards,
  Jay Freedman
  Microsoft Word MVP        FAQ: http://word.mvps.org
  Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
  all may benefit.
date: Fri, 6 Jun 2008 13:15:54 -0400   author:   Michael Koerner

Re: Borders and Shading   
I glad that fellow MVP stepped in to sort that out.  

Re the white space, when you split a table, a paragraph mark is inserted between the two tables, so you will need to apply appropriate formatting to that paragraph mark - probably formatting the font as hidden

The following code splits a table at the row in which the selection is located and then formats the font of the paragraph between the two tables so that it is hidden:

Dim arow As Row
Dim arange As Range
Set arow = Selection.Rows(1)
Selection.Tables(1).Split arow
Set arange = arow.Range
arange.start = arange.start - 1
arange.Collapse wdCollapseStart
arange.Paragraphs(1).Range.Font.Hidden = True


-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

  "Michael Koerner"  wrote in message news:OdDK9j$xIHA.2208@TK2MSFTNGP04.phx.gbl...
  Using this line

  dtable.Split BeforeRow:=newrow 

  seems to work okay. Now how does one go about removing all thw whitespace between the tables?

  -- 

  Regards
  Michael Koerner


    "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
    Michael Koerner wrote:
    > Doug; thanks for taking the time. Greatly appreciated. The macro
    > gives me a Run-time error '5': Invalid procedure call,and when I
    > click on debug the following line is highlighted.
    >
    > If initrng.Characters(1) <> Init Then
    >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
    >         dtable.Split (newrow)
    >         With newrow

    Very interesting behavior...

    When you call a method and you don't use its return value (that is, you use 
    it as a subroutine and not as a function), VBA prefers that you don't 
    enclose the argument in parentheses and in some cases considers it an error 
    (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

    So changing the Split call to

        dtable.Split BeforeRow:=newrow

    or just

       dtable.Split newrow

    will work without errors.

    According to the Help topic on the Split method, the argument can be either 
    a Row object (which newrow is) or the row number. That means you could write 
    the line as

        dtable.Split BeforeRow:=newrow.Index

    or just

       dtable.Split newrow.Index

    But now comes the odd part. You can write the line as

       dtable.Split (newrow.Index)

    and the macro will still work without errors, even though the parentheses 
    are "wrong". But this line gets a compiler error:

       dtable.Split (BeforeRow:=newrow.Index)

    -- 
    Regards,
    Jay Freedman
    Microsoft Word MVP        FAQ: http://word.mvps.org
    Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
    all may benefit.
date: Sat, 7 Jun 2008 18:07:49 +1000   author:   Doug Robbins - Word MVP

Re: Borders and Shading   
Thanks Doug. Where does one insert this in the original macro?

-- 

Regards
Michael Koerner


  "Doug Robbins - Word MVP"  wrote in message news:u8xjXWHyIHA.3968@TK2MSFTNGP04.phx.gbl...
  I glad that fellow MVP stepped in to sort that out.  

  Re the white space, when you split a table, a paragraph mark is inserted between the two tables, so you will need to apply appropriate formatting to that paragraph mark - probably formatting the font as hidden

  The following code splits a table at the row in which the selection is located and then formats the font of the paragraph between the two tables so that it is hidden:

  Dim arow As Row
  Dim arange As Range
  Set arow = Selection.Rows(1)
  Selection.Tables(1).Split arow
  Set arange = arow.Range
  arange.start = arange.start - 1
  arange.Collapse wdCollapseStart
  arange.Paragraphs(1).Range.Font.Hidden = True


  -- 
  Hope this helps.

  Please reply to the newsgroup unless you wish to avail yourself of my
  services on a paid consulting basis.

  Doug Robbins - Word MVP

    "Michael Koerner"  wrote in message news:OdDK9j$xIHA.2208@TK2MSFTNGP04.phx.gbl...
    Using this line

    dtable.Split BeforeRow:=newrow 

    seems to work okay. Now how does one go about removing all thw whitespace between the tables?

    -- 

    Regards
    Michael Koerner


      "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
      Michael Koerner wrote:
      > Doug; thanks for taking the time. Greatly appreciated. The macro
      > gives me a Run-time error '5': Invalid procedure call,and when I
      > click on debug the following line is highlighted.
      >
      > If initrng.Characters(1) <> Init Then
      >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
      >         dtable.Split (newrow)
      >         With newrow

      Very interesting behavior...

      When you call a method and you don't use its return value (that is, you use 
      it as a subroutine and not as a function), VBA prefers that you don't 
      enclose the argument in parentheses and in some cases considers it an error 
      (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

      So changing the Split call to

          dtable.Split BeforeRow:=newrow

      or just

         dtable.Split newrow

      will work without errors.

      According to the Help topic on the Split method, the argument can be either 
      a Row object (which newrow is) or the row number. That means you could write 
      the line as

          dtable.Split BeforeRow:=newrow.Index

      or just

         dtable.Split newrow.Index

      But now comes the odd part. You can write the line as

         dtable.Split (newrow.Index)

      and the macro will still work without errors, even though the parentheses 
      are "wrong". But this line gets a compiler error:

         dtable.Split (BeforeRow:=newrow.Index)

      -- 
      Regards,
      Jay Freedman
      Microsoft Word MVP        FAQ: http://word.mvps.org
      Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
      all may benefit.
date: Sat, 7 Jun 2008 05:48:34 -0400   author:   Michael Koerner

Re: Borders and Shading   
Here is your original macro with all of the required modifications:

Sub InsertFramedHeadRow()
' insert a framed header row into the table
Dim i As Long, j As Long
Dim Init As String
Dim newrow As Row
Dim initrng As Range, arange As Range
Dim dtable As Table
Set dtable = Selection.Tables(1)
j = dtable.Rows.Count
Init = dtable.Cell(j, 1).Range.Characters(1)
For i = j To 1 Step -1
    Set initrng = dtable.Cell(i, 1).Range
    If initrng.Characters(1) <> Init Then
        dtable.Split newrow
        Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
        Set arange = newrow.Range
        arange.start = arange.start - 1
        arange.Collapse wdCollapseStart
        arange.Paragraphs(1).Range.Font.Hidden = True
        With newrow
            .Cells.Merge
            .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Range.Text = "- " & Init & " -"
            .Range.Font.Bold = True
            .Range.Shading _
                .BackgroundPatternColor = wdColorGray10
                .Height = InchesToPoints(0.24)
                .Borders.Enable = wdLineStyleSingle
                .Borders.OutsideLineWidth = wdLineWidth100pt
        End With
        Init = initrng.Characters(1)
    End If
Next i
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
With newrow
    .Cells.Merge
    .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Range.Text = Init
    .Range.Font.Bold = True
    .Range.Shading.BackgroundPatternColor = wdColorGray10
End With
End Sub

Note that if you the paragraph marks ¶ being displayed in the document, the space between the tables will still appear, but if you click on the ¶ (Show/Hide) button to hide the paragraph marks, the space will disappear.  In the Tools>Options>Print dialog, you must also have it set so that Hidden text is not printed.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

  "Michael Koerner"  wrote in message news:OwDHqOIyIHA.2360@TK2MSFTNGP05.phx.gbl...
  Thanks Doug. Where does one insert this in the original macro?

  -- 

  Regards
  Michael Koerner


    "Doug Robbins - Word MVP"  wrote in message news:u8xjXWHyIHA.3968@TK2MSFTNGP04.phx.gbl...
    I glad that fellow MVP stepped in to sort that out.  

    Re the white space, when you split a table, a paragraph mark is inserted between the two tables, so you will need to apply appropriate formatting to that paragraph mark - probably formatting the font as hidden

    The following code splits a table at the row in which the selection is located and then formats the font of the paragraph between the two tables so that it is hidden:

    Dim arow As Row
    Dim arange As Range
    Set arow = Selection.Rows(1)
    Selection.Tables(1).Split arow
    Set arange = arow.Range
    arange.start = arange.start - 1
    arange.Collapse wdCollapseStart
    arange.Paragraphs(1).Range.Font.Hidden = True


    -- 
    Hope this helps.

    Please reply to the newsgroup unless you wish to avail yourself of my
    services on a paid consulting basis.

    Doug Robbins - Word MVP

      "Michael Koerner"  wrote in message news:OdDK9j$xIHA.2208@TK2MSFTNGP04.phx.gbl...
      Using this line

      dtable.Split BeforeRow:=newrow 

      seems to work okay. Now how does one go about removing all thw whitespace between the tables?

      -- 

      Regards
      Michael Koerner


        "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
        Michael Koerner wrote:
        > Doug; thanks for taking the time. Greatly appreciated. The macro
        > gives me a Run-time error '5': Invalid procedure call,and when I
        > click on debug the following line is highlighted.
        >
        > If initrng.Characters(1) <> Init Then
        >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
        >         dtable.Split (newrow)
        >         With newrow

        Very interesting behavior...

        When you call a method and you don't use its return value (that is, you use 
        it as a subroutine and not as a function), VBA prefers that you don't 
        enclose the argument in parentheses and in some cases considers it an error 
        (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

        So changing the Split call to

            dtable.Split BeforeRow:=newrow

        or just

           dtable.Split newrow

        will work without errors.

        According to the Help topic on the Split method, the argument can be either 
        a Row object (which newrow is) or the row number. That means you could write 
        the line as

            dtable.Split BeforeRow:=newrow.Index

        or just

           dtable.Split newrow.Index

        But now comes the odd part. You can write the line as

           dtable.Split (newrow.Index)

        and the macro will still work without errors, even though the parentheses 
        are "wrong". But this line gets a compiler error:

           dtable.Split (BeforeRow:=newrow.Index)

        -- 
        Regards,
        Jay Freedman
        Microsoft Word MVP        FAQ: http://word.mvps.org
        Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
        all may benefit.
date: Sun, 8 Jun 2008 07:25:12 +1000   author:   Doug Robbins - Word MVP

Re: Borders and Shading   
Doug;

Thanks very much. Tried the macro a number of times, and each time I got the message the Word was recovering my document and if I wanted to send an error report to Microsoft.

-- 

Regards
Michael Koerner


  "Doug Robbins - Word MVP"  wrote in message news:%23Na97TOyIHA.3384@TK2MSFTNGP03.phx.gbl...
  Here is your original macro with all of the required modifications:

  Sub InsertFramedHeadRow()
  ' insert a framed header row into the table
  Dim i As Long, j As Long
  Dim Init As String
  Dim newrow As Row
  Dim initrng As Range, arange As Range
  Dim dtable As Table
  Set dtable = Selection.Tables(1)
  j = dtable.Rows.Count
  Init = dtable.Cell(j, 1).Range.Characters(1)
  For i = j To 1 Step -1
      Set initrng = dtable.Cell(i, 1).Range
      If initrng.Characters(1) <> Init Then
          dtable.Split newrow
          Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
          Set arange = newrow.Range
          arange.start = arange.start - 1
          arange.Collapse wdCollapseStart
          arange.Paragraphs(1).Range.Font.Hidden = True
          With newrow
              .Cells.Merge
              .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
              .Range.Text = "- " & Init & " -"
              .Range.Font.Bold = True
              .Range.Shading _
                  .BackgroundPatternColor = wdColorGray10
                  .Height = InchesToPoints(0.24)
                  .Borders.Enable = wdLineStyleSingle
                  .Borders.OutsideLineWidth = wdLineWidth100pt
          End With
          Init = initrng.Characters(1)
      End If
  Next i
  Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
  With newrow
      .Cells.Merge
      .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Range.Text = Init
      .Range.Font.Bold = True
      .Range.Shading.BackgroundPatternColor = wdColorGray10
  End With
  End Sub

  Note that if you the paragraph marks ¶ being displayed in the document, the space between the tables will still appear, but if you click on the ¶ (Show/Hide) button to hide the paragraph marks, the space will disappear.  In the Tools>Options>Print dialog, you must also have it set so that Hidden text is not printed.

  -- 
  Hope this helps.

  Please reply to the newsgroup unless you wish to avail yourself of my
  services on a paid consulting basis.

  Doug Robbins - Word MVP

    "Michael Koerner"  wrote in message news:OwDHqOIyIHA.2360@TK2MSFTNGP05.phx.gbl...
    Thanks Doug. Where does one insert this in the original macro?

    -- 

    Regards
    Michael Koerner


      "Doug Robbins - Word MVP"  wrote in message news:u8xjXWHyIHA.3968@TK2MSFTNGP04.phx.gbl...
      I glad that fellow MVP stepped in to sort that out.  

      Re the white space, when you split a table, a paragraph mark is inserted between the two tables, so you will need to apply appropriate formatting to that paragraph mark - probably formatting the font as hidden

      The following code splits a table at the row in which the selection is located and then formats the font of the paragraph between the two tables so that it is hidden:

      Dim arow As Row
      Dim arange As Range
      Set arow = Selection.Rows(1)
      Selection.Tables(1).Split arow
      Set arange = arow.Range
      arange.start = arange.start - 1
      arange.Collapse wdCollapseStart
      arange.Paragraphs(1).Range.Font.Hidden = True


      -- 
      Hope this helps.

      Please reply to the newsgroup unless you wish to avail yourself of my
      services on a paid consulting basis.

      Doug Robbins - Word MVP

        "Michael Koerner"  wrote in message news:OdDK9j$xIHA.2208@TK2MSFTNGP04.phx.gbl...
        Using this line

        dtable.Split BeforeRow:=newrow 

        seems to work okay. Now how does one go about removing all thw whitespace between the tables?

        -- 

        Regards
        Michael Koerner


          "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
          Michael Koerner wrote:
          > Doug; thanks for taking the time. Greatly appreciated. The macro
          > gives me a Run-time error '5': Invalid procedure call,and when I
          > click on debug the following line is highlighted.
          >
          > If initrng.Characters(1) <> Init Then
          >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
          >         dtable.Split (newrow)
          >         With newrow

          Very interesting behavior...

          When you call a method and you don't use its return value (that is, you use 
          it as a subroutine and not as a function), VBA prefers that you don't 
          enclose the argument in parentheses and in some cases considers it an error 
          (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

          So changing the Split call to

              dtable.Split BeforeRow:=newrow

          or just

             dtable.Split newrow

          will work without errors.

          According to the Help topic on the Split method, the argument can be either 
          a Row object (which newrow is) or the row number. That means you could write 
          the line as

              dtable.Split BeforeRow:=newrow.Index

          or just

             dtable.Split newrow.Index

          But now comes the odd part. You can write the line as

             dtable.Split (newrow.Index)

          and the macro will still work without errors, even though the parentheses 
          are "wrong". But this line gets a compiler error:

             dtable.Split (BeforeRow:=newrow.Index)

          -- 
          Regards,
          Jay Freedman
          Microsoft Word MVP        FAQ: http://word.mvps.org
          Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
          all may benefit.
date: Sat, 7 Jun 2008 18:48:30 -0400   author:   Michael Koerner

Re: Borders and Shading   
Sorry, the Split command was in the wrong place.  The following one should work:

Sub InsertFramedHeadRow()
' insert a framed header row into the table
Dim i As Long, j As Long
Dim Init As String
Dim newrow As Row
Dim initrng As Range, arange As Range
Dim dtable As Table
Set dtable = Selection.Tables(1)
j = dtable.Rows.Count
Init = dtable.Cell(j, 1).Range.Characters(1)
For i = j To 1 Step -1
    Set initrng = dtable.Cell(i, 1).Range
    If initrng.Characters(1) <> Init Then
        Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
        dtable.Split newrow
        Set arange = newrow.Range
        arange.Start = arange.Start - 1
        arange.Collapse wdCollapseStart
        arange.Paragraphs(1).Range.Font.Hidden = True
        With newrow
            .Cells.Merge
            .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Range.Text = "- " & Init & " -"
            .Range.Font.Bold = True
            .Range.Shading _
                .BackgroundPatternColor = wdColorGray10
                .Height = InchesToPoints(0.24)
                .Borders.Enable = wdLineStyleSingle
                .Borders.OutsideLineWidth = wdLineWidth100pt
        End With
        Init = initrng.Characters(1)
    End If
Next i
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
With newrow
    .Cells.Merge
    .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Range.Text = Init
    .Range.Font.Bold = True
    .Range.Shading.BackgroundPatternColor = wdColorGray10
End With
End Sub


-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

  "Michael Koerner"  wrote in message news:uxIoeCPyIHA.3384@TK2MSFTNGP03.phx.gbl...
  Doug;

  Thanks very much. Tried the macro a number of times, and each time I got the message the Word was recovering my document and if I wanted to send an error report to Microsoft.

  -- 

  Regards
  Michael Koerner


    "Doug Robbins - Word MVP"  wrote in message news:%23Na97TOyIHA.3384@TK2MSFTNGP03.phx.gbl...
    Here is your original macro with all of the required modifications:

    Sub InsertFramedHeadRow()
    ' insert a framed header row into the table
    Dim i As Long, j As Long
    Dim Init As String
    Dim newrow As Row
    Dim initrng As Range, arange As Range
    Dim dtable As Table
    Set dtable = Selection.Tables(1)
    j = dtable.Rows.Count
    Init = dtable.Cell(j, 1).Range.Characters(1)
    For i = j To 1 Step -1
        Set initrng = dtable.Cell(i, 1).Range
        If initrng.Characters(1) <> Init Then
            dtable.Split newrow
            Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
            Set arange = newrow.Range
            arange.start = arange.start - 1
            arange.Collapse wdCollapseStart
            arange.Paragraphs(1).Range.Font.Hidden = True
            With newrow
                .Cells.Merge
                .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                .Range.Text = "- " & Init & " -"
                .Range.Font.Bold = True
                .Range.Shading _
                    .BackgroundPatternColor = wdColorGray10
                    .Height = InchesToPoints(0.24)
                    .Borders.Enable = wdLineStyleSingle
                    .Borders.OutsideLineWidth = wdLineWidth100pt
            End With
            Init = initrng.Characters(1)
        End If
    Next i
    Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
    With newrow
        .Cells.Merge
        .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Range.Text = Init
        .Range.Font.Bold = True
        .Range.Shading.BackgroundPatternColor = wdColorGray10
    End With
    End Sub

    Note that if you the paragraph marks ¶ being displayed in the document, the space between the tables will still appear, but if you click on the ¶ (Show/Hide) button to hide the paragraph marks, the space will disappear.  In the Tools>Options>Print dialog, you must also have it set so that Hidden text is not printed.

    -- 
    Hope this helps.

    Please reply to the newsgroup unless you wish to avail yourself of my
    services on a paid consulting basis.

    Doug Robbins - Word MVP

      "Michael Koerner"  wrote in message news:OwDHqOIyIHA.2360@TK2MSFTNGP05.phx.gbl...
      Thanks Doug. Where does one insert this in the original macro?

      -- 

      Regards
      Michael Koerner


        "Doug Robbins - Word MVP"  wrote in message news:u8xjXWHyIHA.3968@TK2MSFTNGP04.phx.gbl...
        I glad that fellow MVP stepped in to sort that out.  

        Re the white space, when you split a table, a paragraph mark is inserted between the two tables, so you will need to apply appropriate formatting to that paragraph mark - probably formatting the font as hidden

        The following code splits a table at the row in which the selection is located and then formats the font of the paragraph between the two tables so that it is hidden:

        Dim arow As Row
        Dim arange As Range
        Set arow = Selection.Rows(1)
        Selection.Tables(1).Split arow
        Set arange = arow.Range
        arange.start = arange.start - 1
        arange.Collapse wdCollapseStart
        arange.Paragraphs(1).Range.Font.Hidden = True


        -- 
        Hope this helps.

        Please reply to the newsgroup unless you wish to avail yourself of my
        services on a paid consulting basis.

        Doug Robbins - Word MVP

          "Michael Koerner"  wrote in message news:OdDK9j$xIHA.2208@TK2MSFTNGP04.phx.gbl...
          Using this line

          dtable.Split BeforeRow:=newrow 

          seems to work okay. Now how does one go about removing all thw whitespace between the tables?

          -- 

          Regards
          Michael Koerner


            "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
            Michael Koerner wrote:
            > Doug; thanks for taking the time. Greatly appreciated. The macro
            > gives me a Run-time error '5': Invalid procedure call,and when I
            > click on debug the following line is highlighted.
            >
            > If initrng.Characters(1) <> Init Then
            >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
            >         dtable.Split (newrow)
            >         With newrow

            Very interesting behavior...

            When you call a method and you don't use its return value (that is, you use 
            it as a subroutine and not as a function), VBA prefers that you don't 
            enclose the argument in parentheses and in some cases considers it an error 
            (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

            So changing the Split call to

                dtable.Split BeforeRow:=newrow

            or just

               dtable.Split newrow

            will work without errors.

            According to the Help topic on the Split method, the argument can be either 
            a Row object (which newrow is) or the row number. That means you could write 
            the line as

                dtable.Split BeforeRow:=newrow.Index

            or just

               dtable.Split newrow.Index

            But now comes the odd part. You can write the line as

               dtable.Split (newrow.Index)

            and the macro will still work without errors, even though the parentheses 
            are "wrong". But this line gets a compiler error:

               dtable.Split (BeforeRow:=newrow.Index)

            -- 
            Regards,
            Jay Freedman
            Microsoft Word MVP        FAQ: http://word.mvps.org
            Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
            all may benefit.
date: Sun, 8 Jun 2008 18:08:39 +1000   author:   Doug Robbins - Word MVP

Re: Borders and Shading   
Worked like a charm. thank you very much for all the time and effort. Greatly appreciated.

-- 

Regards
Michael Koerner


  "Doug Robbins - Word MVP"  wrote in message news:%23DvZg7TyIHA.2064@TK2MSFTNGP05.phx.gbl...
  Sorry, the Split command was in the wrong place.  The following one should work:

  Sub InsertFramedHeadRow()
  ' insert a framed header row into the table
  Dim i As Long, j As Long
  Dim Init As String
  Dim newrow As Row
  Dim initrng As Range, arange As Range
  Dim dtable As Table
  Set dtable = Selection.Tables(1)
  j = dtable.Rows.Count
  Init = dtable.Cell(j, 1).Range.Characters(1)
  For i = j To 1 Step -1
      Set initrng = dtable.Cell(i, 1).Range
      If initrng.Characters(1) <> Init Then
          Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
          dtable.Split newrow
          Set arange = newrow.Range
          arange.Start = arange.Start - 1
          arange.Collapse wdCollapseStart
          arange.Paragraphs(1).Range.Font.Hidden = True
          With newrow
              .Cells.Merge
              .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
              .Range.Text = "- " & Init & " -"
              .Range.Font.Bold = True
              .Range.Shading _
                  .BackgroundPatternColor = wdColorGray10
                  .Height = InchesToPoints(0.24)
                  .Borders.Enable = wdLineStyleSingle
                  .Borders.OutsideLineWidth = wdLineWidth100pt
          End With
          Init = initrng.Characters(1)
      End If
  Next i
  Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
  With newrow
      .Cells.Merge
      .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
      .Range.Text = Init
      .Range.Font.Bold = True
      .Range.Shading.BackgroundPatternColor = wdColorGray10
  End With
  End Sub


  -- 
  Hope this helps.

  Please reply to the newsgroup unless you wish to avail yourself of my
  services on a paid consulting basis.

  Doug Robbins - Word MVP

    "Michael Koerner"  wrote in message news:uxIoeCPyIHA.3384@TK2MSFTNGP03.phx.gbl...
    Doug;

    Thanks very much. Tried the macro a number of times, and each time I got the message the Word was recovering my document and if I wanted to send an error report to Microsoft.

    -- 

    Regards
    Michael Koerner


      "Doug Robbins - Word MVP"  wrote in message news:%23Na97TOyIHA.3384@TK2MSFTNGP03.phx.gbl...
      Here is your original macro with all of the required modifications:

      Sub InsertFramedHeadRow()
      ' insert a framed header row into the table
      Dim i As Long, j As Long
      Dim Init As String
      Dim newrow As Row
      Dim initrng As Range, arange As Range
      Dim dtable As Table
      Set dtable = Selection.Tables(1)
      j = dtable.Rows.Count
      Init = dtable.Cell(j, 1).Range.Characters(1)
      For i = j To 1 Step -1
          Set initrng = dtable.Cell(i, 1).Range
          If initrng.Characters(1) <> Init Then
              dtable.Split newrow
              Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
              Set arange = newrow.Range
              arange.start = arange.start - 1
              arange.Collapse wdCollapseStart
              arange.Paragraphs(1).Range.Font.Hidden = True
              With newrow
                  .Cells.Merge
                  .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                  .Range.Text = "- " & Init & " -"
                  .Range.Font.Bold = True
                  .Range.Shading _
                      .BackgroundPatternColor = wdColorGray10
                      .Height = InchesToPoints(0.24)
                      .Borders.Enable = wdLineStyleSingle
                      .Borders.OutsideLineWidth = wdLineWidth100pt
              End With
              Init = initrng.Characters(1)
          End If
      Next i
      Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
      With newrow
          .Cells.Merge
          .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
          .Range.Text = Init
          .Range.Font.Bold = True
          .Range.Shading.BackgroundPatternColor = wdColorGray10
      End With
      End Sub

      Note that if you the paragraph marks ¶ being displayed in the document, the space between the tables will still appear, but if you click on the ¶ (Show/Hide) button to hide the paragraph marks, the space will disappear.  In the Tools>Options>Print dialog, you must also have it set so that Hidden text is not printed.

      -- 
      Hope this helps.

      Please reply to the newsgroup unless you wish to avail yourself of my
      services on a paid consulting basis.

      Doug Robbins - Word MVP

        "Michael Koerner"  wrote in message news:OwDHqOIyIHA.2360@TK2MSFTNGP05.phx.gbl...
        Thanks Doug. Where does one insert this in the original macro?

        -- 

        Regards
        Michael Koerner


          "Doug Robbins - Word MVP"  wrote in message news:u8xjXWHyIHA.3968@TK2MSFTNGP04.phx.gbl...
          I glad that fellow MVP stepped in to sort that out.  

          Re the white space, when you split a table, a paragraph mark is inserted between the two tables, so you will need to apply appropriate formatting to that paragraph mark - probably formatting the font as hidden

          The following code splits a table at the row in which the selection is located and then formats the font of the paragraph between the two tables so that it is hidden:

          Dim arow As Row
          Dim arange As Range
          Set arow = Selection.Rows(1)
          Selection.Tables(1).Split arow
          Set arange = arow.Range
          arange.start = arange.start - 1
          arange.Collapse wdCollapseStart
          arange.Paragraphs(1).Range.Font.Hidden = True


          -- 
          Hope this helps.

          Please reply to the newsgroup unless you wish to avail yourself of my
          services on a paid consulting basis.

          Doug Robbins - Word MVP

            "Michael Koerner"  wrote in message news:OdDK9j$xIHA.2208@TK2MSFTNGP04.phx.gbl...
            Using this line

            dtable.Split BeforeRow:=newrow 

            seems to work okay. Now how does one go about removing all thw whitespace between the tables?

            -- 

            Regards
            Michael Koerner


              "Jay Freedman"  wrote in message news:eHijXZ%23xIHA.4704@TK2MSFTNGP03.phx.gbl...
              Michael Koerner wrote:
              > Doug; thanks for taking the time. Greatly appreciated. The macro
              > gives me a Run-time error '5': Invalid procedure call,and when I
              > click on debug the following line is highlighted.
              >
              > If initrng.Characters(1) <> Init Then
              >         Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i  1))
              >         dtable.Split (newrow)
              >         With newrow

              Very interesting behavior...

              When you call a method and you don't use its return value (that is, you use 
              it as a subroutine and not as a function), VBA prefers that you don't 
              enclose the argument in parentheses and in some cases considers it an error 
              (http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm).

              So changing the Split call to

                  dtable.Split BeforeRow:=newrow

              or just

                 dtable.Split newrow

              will work without errors.

              According to the Help topic on the Split method, the argument can be either 
              a Row object (which newrow is) or the row number. That means you could write 
              the line as

                  dtable.Split BeforeRow:=newrow.Index

              or just

                 dtable.Split newrow.Index

              But now comes the odd part. You can write the line as

                 dtable.Split (newrow.Index)

              and the macro will still work without errors, even though the parentheses 
              are "wrong". But this line gets a compiler error:

                 dtable.Split (BeforeRow:=newrow.Index)

              -- 
              Regards,
              Jay Freedman
              Microsoft Word MVP        FAQ: http://word.mvps.org
              Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
              all may benefit.
date: Sun, 8 Jun 2008 09:35:29 -0400   author:   Michael Koerner

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us