I'd like to create a macro to move the position of a table, based on it's current position

M

Mike

I've written a very helpful macro that will find a certain table in a
document, erase it, and create an updated table, complete with all the
necessary items the table should contain.

I only have one very small issue. In each document, the position of
the table may be in a slightly different position to the left or right.
What I would like to create is two other macros so that each time I
run it, it will move the position of the table 1/100th of an inch - one
to go left and one to go right.

What I was picturing is a line that would read something like...

If Selection.Tables(1).Rows.LeftIndent = InchesToPoints(0.15) Then
Selection.Tables(1).Rows.LeftIndent = InchesToPoints(0.14)
End If

.... and so on. I planned on repeating the lines a bunch of times to
incorporate different distances.

Of course, that command does absolutely nothing when I try it. Does
anyone have any ideas what would work? Could I be missing something
very simple here or am I just approaching this with the wrong idea?


Thanks in advance,

- Mike
 
D

Doug Robbins - Word MVP

The following will move it one point (1/72 of an inch)

Sub MoveTableLeft()
With Selection.Tables(1).Rows
If .LeftIndent >= 1 Then
.LeftIndent = .LeftIndent - 1
Else
MsgBox "Table cannot be moved further to the left"
End If
End With
End Sub

Sub MoveTableRight()
With Selection.Tables(1).Rows
.LeftIndent = .LeftIndent + 1
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
 
J

Jean-Guy Marcil

Mike was telling us:
Mike nous racontait que :
I've written a very helpful macro that will find a certain table in a
document, erase it, and create an updated table, complete with all the
necessary items the table should contain.

I only have one very small issue. In each document, the position of
the table may be in a slightly different position to the left or
right. What I would like to create is two other macros so that each
time I run it, it will move the position of the table 1/100th of an
inch - one to go left and one to go right.

What I was picturing is a line that would read something like...

If Selection.Tables(1).Rows.LeftIndent = InchesToPoints(0.15) Then
Selection.Tables(1).Rows.LeftIndent = InchesToPoints(0.14)
End If

Are you sure your target table is set to a left indent of 0.15"? If not,
then nothing happens!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Mike

Doug said:
The following will move it one point (1/72 of an inch)

Sub MoveTableLeft()
With Selection.Tables(1).Rows
If .LeftIndent >= 1 Then
.LeftIndent = .LeftIndent - 1
Else
MsgBox "Table cannot be moved further to the left"
End If
End With
End Sub

Sub MoveTableRight()
With Selection.Tables(1).Rows
.LeftIndent = .LeftIndent + 1
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

Doug, that was perfect. Thank you!!!
 
M

Mike

Are you sure your target table is set to a left indent of 0.15"? If not,
then nothing happens!

Yes, Jean-Guy, I'm positive. Doug's macro is much better than what I
was trying to accomplish anyway.
 

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