Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-09-2021, 09:30 PM
Wild Bee Wild Bee is offline Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Windows 10 Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Office 2019
Novice
Macro to change each individual cell to 0 padding, one at a time in a table with merged cells.
 
Join Date: Feb 2021
Posts: 7
Wild Bee is on a distinguished road
Default Macro to change each individual cell to 0 padding, one at a time in a table with merged cells.


Hi.

I have scoured the net for days now, and even though I've found a couple of macros that work when the table has no merged cells, or does the whole document, I haven't found a macro that will check each cell in a table and change it's margins/padding.

I've discovered that for Word, each individual cell in the table has it's own margins, which overrule any changes to the table as a whole. The only way I can remove all white space from within a table, is to click on each cell and change it's margins to 0, or tick the box that says "same as whole table". Selecting the whole table and changing these numbers does diddly-squat to the individual cells.

I've done a simple macro that I can run manually for each cell, but I am converting documents that have anything from 200 pages to 700 pages of tables. The tables are specialized in this business (Aviation), so they MUST remain exactly as they already are when it comes to shape, borders and size. I will control the space around the text using paragraph formatting.

I can sort of decipher and "read" macro's, but am not that familiar with VBA, so would really appreciate if someone could please write me a VBA that will check each cell within a selected table, regardless if merged, and change the margin/padding to 0.

Thanks.
Reply With Quote
  #2  
Old 02-09-2021, 09:37 PM
gmayor's Avatar
gmayor gmayor is offline Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Windows 10 Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

How about
Code:
Sub Macro1()
Dim oCell As Cell
Dim oTable As Table
    Set oTable = Selection.Tables(1)
    For Each oCell In oTable.Range.Cells
        With oCell
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0)
            .RightPadding = InchesToPoints(0)
        End With
    Next oCell
End Sub
or for all the tables
Code:
Sub Macro2()
Dim oCell As Cell
Dim oTable As Table
    For Each oTable In ActiveDocument.Tables
        For Each oCell In oTable.Range.Cells
            With oCell
                .TopPadding = InchesToPoints(0)
                .BottomPadding = InchesToPoints(0)
                .LeftPadding = InchesToPoints(0)
                .RightPadding = InchesToPoints(0)
            End With
        Next oCell
        DoEvents
    Next oTable
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-09-2021, 10:33 PM
Wild Bee Wild Bee is offline Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Windows 10 Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Office 2019
Novice
Macro to change each individual cell to 0 padding, one at a time in a table with merged cells.
 
Join Date: Feb 2021
Posts: 7
Wild Bee is on a distinguished road
Talking Thankyou!!

You awesome person!! Thank you! The single one worked awesomely. I'll try the other one, but even just the first one is fantastic.

I need to learn how to write VBA..
LOL


Quote:
Originally Posted by gmayor View Post
How about
Code:
Sub Macro1()
Dim oCell As Cell
Dim oTable As Table
    Set oTable = Selection.Tables(1)
    For Each oCell In oTable.Range.Cells
        With oCell
            .TopPadding = InchesToPoints(0)
            .BottomPadding = InchesToPoints(0)
            .LeftPadding = InchesToPoints(0)
            .RightPadding = InchesToPoints(0)
        End With
    Next oCell
End Sub
or for all the tables
Code:
Sub Macro2()
Dim oCell As Cell
Dim oTable As Table
    For Each oTable In ActiveDocument.Tables
        For Each oCell In oTable.Range.Cells
            With oCell
                .TopPadding = InchesToPoints(0)
                .BottomPadding = InchesToPoints(0)
                .LeftPadding = InchesToPoints(0)
                .RightPadding = InchesToPoints(0)
            End With
        Next oCell
        DoEvents
    Next oTable
End Sub
Reply With Quote
  #4  
Old 02-10-2021, 12:44 AM
macropod's Avatar
macropod macropod is offline Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Windows 10 Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by gmayor View Post
How about
Code:
... = InchesToPoints(0)
There is no point in this conversion, using just
Code:
... = 0
would give the same result and be quicker.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Table Row with merged cells andi_bln Word VBA 3 10-15-2020 01:22 AM
How to get autonumber series if adjacent cell has merged cells? kingston123 Excel 3 06-28-2020 09:12 AM
Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Converting table to text (and back) with carriage returns in cells, split and merged cells ndajko Word 5 11-04-2019 07:53 AM
Merging 2 different cells containing IF formula & change in cell values based on multiple time frame jay_excel Excel 0 07-29-2017 11:04 PM
Macro to change each individual cell to 0 padding, one at a time in a table with merged cells. Table will not allow sorting because "cells are merged". I can't find the merged cells. wendyloooo Word Tables 1 05-26-2015 01:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft