Table Ident Problem

S

spunkymuffmonkey

Hi all,

I have a problem and wondered if anybody can offer me any advice.

When copying and pasting entire rows from one table to another I sometimes
hit an column alignmnet problem.

To explain (I'll be as brief as I can) we use documents to record client
info that we call a 'Running Record' (RR), these Running Records are word
docs with a table in, the tables have 4 columns and can have any number of
rows depending upon the case.

To complicate matters we have two versions of the running record in use.
both versions have 4 columns, but the widths of these columns are different
and when copying a table row from an old RR to a new or vica versa, the
column alignment gets screwed up, normally resulting in something like the
representation below:

|______|______|______|______|
|______|______|______|______|
|______|______|______|______|
|______|______|______|______|
|______|______|______|______|

Unfortunately, the screw up results (in print layout view) to blow the
columns off the page and looks a mess.

Having rooted around programmatically, nearest thing I can find to fixing it
was the SetLeftIndent method looped through each row:

oRow.SetLeftIndent LeftIndent:=-3.6, RulerStyle:=wdAdjustNone

and although this makes the table look a little better it does not
straighten and align all column widths as perfect as Iw ould like.

Could anybody tell me any other method or shed any light how to prevent or
resolve this annoying issue I have.

Many thanks for looking
 
P

Pesach Shelnitz

Hi,

You said that you cut and pasted a row from one table to another, but you
didn't describe exactly how you did this, so I may not have reproduced the
problem in exactly the same way that you observed it.

I can reproduce your problem by creating two tables that have columns with
different widths. If I select a row in one of the tables by double-clicking
the gridline at the beginning of the row, press Ctrl+C to copy the row to the
clipboard, place my cursor in the first cell of the row where I want the
copied row to be inserted in the other table, and then press Ctrl+V, the
borders of the cells in the row inserted do not match the rest of the table.

However, the problem does not occur when I do as follows:
1. Select the row that I want to copy by placing my cursor just before the
text in the first cell, holding down Shift, and pressing Right exactly 5
times (so that the selection does not protrude out beyond the right border of
the table).
2. Press Ctrl+C to copy the cells to the clipboard.
3. Place my cursor in the first cell of the row where I want the copied row
to be inserted in the other table.
4. Press Left and then Enter to create an empty row (the cursor
automatically moves to the first cell of the new row).
5. Press Ctrl+V.
 
F

Fumei2 via OfficeKB.com

"Could anybody tell me any other method or shed any light how to prevent or
resolve this annoying issue I have."

The best way is to eliminate having two different versions of your table.
Pick one or the other. It would not be too difficult to progammatically
change all your tables to whatever format you decide on.

Pesach said:
Hi,

You said that you cut and pasted a row from one table to another, but you
didn't describe exactly how you did this, so I may not have reproduced the
problem in exactly the same way that you observed it.

I can reproduce your problem by creating two tables that have columns with
different widths. If I select a row in one of the tables by double-clicking
the gridline at the beginning of the row, press Ctrl+C to copy the row to the
clipboard, place my cursor in the first cell of the row where I want the
copied row to be inserted in the other table, and then press Ctrl+V, the
borders of the cells in the row inserted do not match the rest of the table.

However, the problem does not occur when I do as follows:
1. Select the row that I want to copy by placing my cursor just before the
text in the first cell, holding down Shift, and pressing Right exactly 5
times (so that the selection does not protrude out beyond the right border of
the table).
2. Press Ctrl+C to copy the cells to the clipboard.
3. Place my cursor in the first cell of the row where I want the copied row
to be inserted in the other table.
4. Press Left and then Enter to create an empty row (the cursor
automatically moves to the first cell of the new row).
5. Press Ctrl+V.
[quoted text clipped - 35 lines]
Many thanks for looking
 
S

spunkymuffmonkey

Hi Pesach and many thanks for all your time and effort when helping me.

To explain in a little more detail.

These running records (RR - word table 4 columns wide) are saved into a
document management system for the clients we deal with, when I came into
post a version of this RR was used which I thought could be bettered, the old
style used smaller column widths and wider page margins and there were
various other things that could be improved.

So, I redesigned the template used by our users, unfortunately the sheer
amount of old style RR saved into our document management system prevented me
from being able to convert all old style RR's to the new format, so we're
left with two versions of the Running Record in existance.

However I am now working on a way for users to better manager copying &
pasting rows from these running records, all has been well, however when
copying rows from the new style RR to an old one I hit the problem which I
tried to explain previously.

The code I'm using to select and copy a row is:

oSourceDoc.Tables(2).Rows(y).Select
Selection.Copy

where 'y' is a value from a listbox on a user form

and the code to paste is:

Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste

where 'k' is a again a value from a listbox on a userform.

I shall give the selection method I am using a tweak to see what that
results in, I shall tweak by selecting the cells not the entire row as this
is what I think I have gained in knowledge from your previous post.

Sorry to waffle on and thanks again for your time and effort, if any further
information is needed then please let me know as I will regularly check back
for updates.

Cheers

Alex

Fumei2 via OfficeKB.com said:
"Could anybody tell me any other method or shed any light how to prevent or
resolve this annoying issue I have."

The best way is to eliminate having two different versions of your table.
Pick one or the other. It would not be too difficult to progammatically
change all your tables to whatever format you decide on.

Pesach said:
Hi,

You said that you cut and pasted a row from one table to another, but you
didn't describe exactly how you did this, so I may not have reproduced the
problem in exactly the same way that you observed it.

I can reproduce your problem by creating two tables that have columns with
different widths. If I select a row in one of the tables by double-clicking
the gridline at the beginning of the row, press Ctrl+C to copy the row to the
clipboard, place my cursor in the first cell of the row where I want the
copied row to be inserted in the other table, and then press Ctrl+V, the
borders of the cells in the row inserted do not match the rest of the table.

However, the problem does not occur when I do as follows:
1. Select the row that I want to copy by placing my cursor just before the
text in the first cell, holding down Shift, and pressing Right exactly 5
times (so that the selection does not protrude out beyond the right border of
the table).
2. Press Ctrl+C to copy the cells to the clipboard.
3. Place my cursor in the first cell of the row where I want the copied row
to be inserted in the other table.
4. Press Left and then Enter to create an empty row (the cursor
automatically moves to the first cell of the new row).
5. Press Ctrl+V.
[quoted text clipped - 35 lines]
Many thanks for looking

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1

.
 
P

Pesach Shelnitz

Hi Alex,

Yes, you do need to tweak the selection method. Let me try to help you with
this.
The following macro uses a Range object to copy the cells in a table row.
The Range object is first set to the range of the first cell and then
expanded to include all the cells in the row. (The number of cells can differ
from 4.) Then the Range object is copied. When a Range object is used, the
copying is accomplished silently without anything being selected. Before
pasting, a new empty row is added at the end of the target table. After
pasting, the selection is collapsed to the beginning of the row added.

Sub CopyCells()
Dim MyRange As Range
Dim y As Long
Dim k As Long

y = 3
k = 1
With ActiveDocument.Tables(2).Rows(y)
Set MyRange = .Cells(1).Range
MyRange.End = .Cells(.Cells.Count).Range.End
End With
MyRange.Copy
Application.Documents(k).Tables(1).Rows.Add
Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste
Selection.Collapse Direction:=wdCollapseEnd

Set MyRange = Nothing

End Sub

--
Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.com


spunkymuffmonkey said:
Hi Pesach and many thanks for all your time and effort when helping me.

To explain in a little more detail.

These running records (RR - word table 4 columns wide) are saved into a
document management system for the clients we deal with, when I came into
post a version of this RR was used which I thought could be bettered, the old
style used smaller column widths and wider page margins and there were
various other things that could be improved.

So, I redesigned the template used by our users, unfortunately the sheer
amount of old style RR saved into our document management system prevented me
from being able to convert all old style RR's to the new format, so we're
left with two versions of the Running Record in existance.

However I am now working on a way for users to better manager copying &
pasting rows from these running records, all has been well, however when
copying rows from the new style RR to an old one I hit the problem which I
tried to explain previously.

The code I'm using to select and copy a row is:

oSourceDoc.Tables(2).Rows(y).Select
Selection.Copy

where 'y' is a value from a listbox on a user form

and the code to paste is:

Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste

where 'k' is a again a value from a listbox on a userform.

I shall give the selection method I am using a tweak to see what that
results in, I shall tweak by selecting the cells not the entire row as this
is what I think I have gained in knowledge from your previous post.

Sorry to waffle on and thanks again for your time and effort, if any further
information is needed then please let me know as I will regularly check back
for updates.

Cheers

Alex

Fumei2 via OfficeKB.com said:
"Could anybody tell me any other method or shed any light how to prevent or
resolve this annoying issue I have."

The best way is to eliminate having two different versions of your table.
Pick one or the other. It would not be too difficult to progammatically
change all your tables to whatever format you decide on.

Pesach said:
Hi,

You said that you cut and pasted a row from one table to another, but you
didn't describe exactly how you did this, so I may not have reproduced the
problem in exactly the same way that you observed it.

I can reproduce your problem by creating two tables that have columns with
different widths. If I select a row in one of the tables by double-clicking
the gridline at the beginning of the row, press Ctrl+C to copy the row to the
clipboard, place my cursor in the first cell of the row where I want the
copied row to be inserted in the other table, and then press Ctrl+V, the
borders of the cells in the row inserted do not match the rest of the table.

However, the problem does not occur when I do as follows:
1. Select the row that I want to copy by placing my cursor just before the
text in the first cell, holding down Shift, and pressing Right exactly 5
times (so that the selection does not protrude out beyond the right border of
the table).
2. Press Ctrl+C to copy the cells to the clipboard.
3. Place my cursor in the first cell of the row where I want the copied row
to be inserted in the other table.
4. Press Left and then Enter to create an empty row (the cursor
automatically moves to the first cell of the new row).
5. Press Ctrl+V.

Hi all,

[quoted text clipped - 35 lines]

Many thanks for looking

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1

.
 
S

spunkymuffmonkey

Many thanks indeed for this, if there was anyway of repaying you I'd jump at
the chance!

Have a great weekend and take care!

Pesach Shelnitz said:
Hi Alex,

Yes, you do need to tweak the selection method. Let me try to help you with
this.
The following macro uses a Range object to copy the cells in a table row.
The Range object is first set to the range of the first cell and then
expanded to include all the cells in the row. (The number of cells can differ
from 4.) Then the Range object is copied. When a Range object is used, the
copying is accomplished silently without anything being selected. Before
pasting, a new empty row is added at the end of the target table. After
pasting, the selection is collapsed to the beginning of the row added.

Sub CopyCells()
Dim MyRange As Range
Dim y As Long
Dim k As Long

y = 3
k = 1
With ActiveDocument.Tables(2).Rows(y)
Set MyRange = .Cells(1).Range
MyRange.End = .Cells(.Cells.Count).Range.End
End With
MyRange.Copy
Application.Documents(k).Tables(1).Rows.Add
Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste
Selection.Collapse Direction:=wdCollapseEnd

Set MyRange = Nothing

End Sub

--
Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.com


spunkymuffmonkey said:
Hi Pesach and many thanks for all your time and effort when helping me.

To explain in a little more detail.

These running records (RR - word table 4 columns wide) are saved into a
document management system for the clients we deal with, when I came into
post a version of this RR was used which I thought could be bettered, the old
style used smaller column widths and wider page margins and there were
various other things that could be improved.

So, I redesigned the template used by our users, unfortunately the sheer
amount of old style RR saved into our document management system prevented me
from being able to convert all old style RR's to the new format, so we're
left with two versions of the Running Record in existance.

However I am now working on a way for users to better manager copying &
pasting rows from these running records, all has been well, however when
copying rows from the new style RR to an old one I hit the problem which I
tried to explain previously.

The code I'm using to select and copy a row is:

oSourceDoc.Tables(2).Rows(y).Select
Selection.Copy

where 'y' is a value from a listbox on a user form

and the code to paste is:

Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste

where 'k' is a again a value from a listbox on a userform.

I shall give the selection method I am using a tweak to see what that
results in, I shall tweak by selecting the cells not the entire row as this
is what I think I have gained in knowledge from your previous post.

Sorry to waffle on and thanks again for your time and effort, if any further
information is needed then please let me know as I will regularly check back
for updates.

Cheers

Alex

Fumei2 via OfficeKB.com said:
"Could anybody tell me any other method or shed any light how to prevent or
resolve this annoying issue I have."

The best way is to eliminate having two different versions of your table.
Pick one or the other. It would not be too difficult to progammatically
change all your tables to whatever format you decide on.

Pesach Shelnitz wrote:
Hi,

You said that you cut and pasted a row from one table to another, but you
didn't describe exactly how you did this, so I may not have reproduced the
problem in exactly the same way that you observed it.

I can reproduce your problem by creating two tables that have columns with
different widths. If I select a row in one of the tables by double-clicking
the gridline at the beginning of the row, press Ctrl+C to copy the row to the
clipboard, place my cursor in the first cell of the row where I want the
copied row to be inserted in the other table, and then press Ctrl+V, the
borders of the cells in the row inserted do not match the rest of the table.

However, the problem does not occur when I do as follows:
1. Select the row that I want to copy by placing my cursor just before the
text in the first cell, holding down Shift, and pressing Right exactly 5
times (so that the selection does not protrude out beyond the right border of
the table).
2. Press Ctrl+C to copy the cells to the clipboard.
3. Place my cursor in the first cell of the row where I want the copied row
to be inserted in the other table.
4. Press Left and then Enter to create an empty row (the cursor
automatically moves to the first cell of the new row).
5. Press Ctrl+V.

Hi all,

[quoted text clipped - 35 lines]

Many thanks for looking

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1

.
 
S

spunkymuffmonkey

Hi Pesach,

Just thought I would let you know that your advice worked a treat and this
problem is no longer occuring.

Many thanks again

spunkymuffmonkey said:
Many thanks indeed for this, if there was anyway of repaying you I'd jump at
the chance!

Have a great weekend and take care!

Pesach Shelnitz said:
Hi Alex,

Yes, you do need to tweak the selection method. Let me try to help you with
this.
The following macro uses a Range object to copy the cells in a table row.
The Range object is first set to the range of the first cell and then
expanded to include all the cells in the row. (The number of cells can differ
from 4.) Then the Range object is copied. When a Range object is used, the
copying is accomplished silently without anything being selected. Before
pasting, a new empty row is added at the end of the target table. After
pasting, the selection is collapsed to the beginning of the row added.

Sub CopyCells()
Dim MyRange As Range
Dim y As Long
Dim k As Long

y = 3
k = 1
With ActiveDocument.Tables(2).Rows(y)
Set MyRange = .Cells(1).Range
MyRange.End = .Cells(.Cells.Count).Range.End
End With
MyRange.Copy
Application.Documents(k).Tables(1).Rows.Add
Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste
Selection.Collapse Direction:=wdCollapseEnd

Set MyRange = Nothing

End Sub

--
Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.com


spunkymuffmonkey said:
Hi Pesach and many thanks for all your time and effort when helping me.

To explain in a little more detail.

These running records (RR - word table 4 columns wide) are saved into a
document management system for the clients we deal with, when I came into
post a version of this RR was used which I thought could be bettered, the old
style used smaller column widths and wider page margins and there were
various other things that could be improved.

So, I redesigned the template used by our users, unfortunately the sheer
amount of old style RR saved into our document management system prevented me
from being able to convert all old style RR's to the new format, so we're
left with two versions of the Running Record in existance.

However I am now working on a way for users to better manager copying &
pasting rows from these running records, all has been well, however when
copying rows from the new style RR to an old one I hit the problem which I
tried to explain previously.

The code I'm using to select and copy a row is:

oSourceDoc.Tables(2).Rows(y).Select
Selection.Copy

where 'y' is a value from a listbox on a user form

and the code to paste is:

Application.Documents(k).Tables(1).Rows.Last.Select
Selection.Paste

where 'k' is a again a value from a listbox on a userform.

I shall give the selection method I am using a tweak to see what that
results in, I shall tweak by selecting the cells not the entire row as this
is what I think I have gained in knowledge from your previous post.

Sorry to waffle on and thanks again for your time and effort, if any further
information is needed then please let me know as I will regularly check back
for updates.

Cheers

Alex

:

"Could anybody tell me any other method or shed any light how to prevent or
resolve this annoying issue I have."

The best way is to eliminate having two different versions of your table.
Pick one or the other. It would not be too difficult to progammatically
change all your tables to whatever format you decide on.

Pesach Shelnitz wrote:
Hi,

You said that you cut and pasted a row from one table to another, but you
didn't describe exactly how you did this, so I may not have reproduced the
problem in exactly the same way that you observed it.

I can reproduce your problem by creating two tables that have columns with
different widths. If I select a row in one of the tables by double-clicking
the gridline at the beginning of the row, press Ctrl+C to copy the row to the
clipboard, place my cursor in the first cell of the row where I want the
copied row to be inserted in the other table, and then press Ctrl+V, the
borders of the cells in the row inserted do not match the rest of the table.

However, the problem does not occur when I do as follows:
1. Select the row that I want to copy by placing my cursor just before the
text in the first cell, holding down Shift, and pressing Right exactly 5
times (so that the selection does not protrude out beyond the right border of
the table).
2. Press Ctrl+C to copy the cells to the clipboard.
3. Place my cursor in the first cell of the row where I want the copied row
to be inserted in the other table.
4. Press Left and then Enter to create an empty row (the cursor
automatically moves to the first cell of the new row).
5. Press Ctrl+V.

Hi all,

[quoted text clipped - 35 lines]

Many thanks for looking

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201002/1

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top