Consulting

Results 1 to 6 of 6

Thread: Solved: Table Margins

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    Solved: Table Margins

    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?

    [vba]
    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
    [/vba]

    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?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Try this one with 2 loops. (Great more loops) :[vba]
    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
    [/vba]

    HTH.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    wow... MOS to the rescue yet again! Thanks man.

    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

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by TrippyTom
    wow... MOS to the rescue yet again! Thanks man.
    You're most welcom!

    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!

    Till next time...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    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

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    See you other thread for the correct code.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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