PDA

View Full Version : Solved: Table Margins



TrippyTom
07-12-2006, 12:35 PM
Hi guys,

I have a question. The following macro works to reset all margins on shapes, but I have to put it in a loop and repeat it 3 or 4 times to get table margins to be set to zero. Any idea why?

Am I doing something wrong?


Sub ResetMargins()

On Error GoTo Nirvana
With ActiveWindow.Selection.ShapeRange
.TextFrame.MarginLeft = 0
.TextFrame.MarginRight = 0
.TextFrame.MarginTop = 0
.TextFrame.MarginBottom = 0
End With

Nirvana:
End Sub


EDIT: Actually the loop isn't working either. If I manually run the macro a few times, it works, but not via a loop. What the heck is going on? :think:

MOS MASTER
07-12-2006, 02:24 PM
Hi, :hi:

Try this one with 2 loops. (Great more loops) :*) :
Sub SetMySelectedTableMargins()
Dim TBLShape As Table
Dim TBLCell As Cell
Dim iCell As Integer
Set TBLShape = ActiveWindow.Selection.ShapeRange.Table
For iCell = 1 To TBLShape.Rows.Count
For Each TBLCell In TBLShape.Rows(iCell).Cells
With TBLCell.Shape.TextFrame
.MarginTop = 0
.MarginLeft = 0
.MarginRight = 0
.MarginBottom = 0
End With
Next
Next
Set TBLCell = Nothing
Set TBLShape = Nothing
End Sub


HTH. :whistle:

TrippyTom
07-12-2006, 02:40 PM
wow... MOS to the rescue yet again! Thanks man. :friends:

Can you explain why 2 loops would force this to work? Did I inadvertantly find a "glitch", or was my code just not very good?

If I understand your code correctly, it's going through each cell in each row and setting it, right?

p.s. -- your code at the end made me giggle because I read the ongoing post about setting everything back to nothing. I should get into that habit I guess. ;)

-TT

MOS MASTER
07-12-2006, 02:48 PM
wow... MOS to the rescue yet again! Thanks man. :friends:
You're most welcom! :beerchug:



Can you explain why 2 loops would force this to work? Did I inadvertantly find a "glitch", or was my code just not very good? The need for two loops (As I coded it now) was to make sure I had a pointer to loop trough all the rows to reset them. (pointer iCell)



If I understand your code correctly, it's going through each cell in each row and setting it, right?
Exactly! :)



p.s. -- your code at the end made me giggle because I read the ongoing post about setting everything back to nothing. I should get into that habit I guess. ;)

-TT

You can make your own dissicion 'bout that. You've read the post so you know by now where I stand on Code Netiquette. And believe me we have those discussions to stay up to date and learn from each other and have some great laughs along the way! :rofl:

Till next time...

magnel
07-19-2013, 10:50 PM
Hello MOS,

Like the powerpoint table margins set to zero in all the cells, is it possible to set the indent to zero in all the cells of the table.

have pasted some pictures about the cells indent.
http://www.vbaexpress.com/forum/showthread.php?t=46882

Regards,
Rafael

John Wilson
07-25-2013, 06:04 AM
See you other thread for the correct code.