Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2024, 01:37 AM
woocash_11 woocash_11 is offline Height of all rows of all tables set as "at least". Windows 11 Height of all rows of all tables set as "at least". Office 2021
Novice
Height of all rows of all tables set as "at least".
 
Join Date: Mar 2024
Posts: 4
woocash_11 is on a distinguished road
Default Height of all rows of all tables set as "at least".

Hi guys,



as in the title, I need a VBA code that sets height of all rows in all tables in document as "at least" but without changing the value of the height, so when the volume of text in the cell increases, the cell expands, but when it decreases the cell DOES NOT shrink.

I would appreciate any help
Reply With Quote
  #2  
Old 03-17-2024, 01:54 AM
vivka vivka is offline Height of all rows of all tables set as "at least". Windows 7 64bit Height of all rows of all tables set as "at least". Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, Woocash_11! Try this:

Code:
Sub Tbls_Format_1()
'Format all tables in active doc.

Dim oTbl As word.Table
    For Each oTbl In ActiveDocument.Tables
        oTbl.rows.HeightRule = wdRowHeightAtLeast   
    Next oTbl
End Sub
Reply With Quote
  #3  
Old 03-17-2024, 02:12 AM
woocash_11 woocash_11 is offline Height of all rows of all tables set as "at least". Windows 11 Height of all rows of all tables set as "at least". Office 2021
Novice
Height of all rows of all tables set as "at least".
 
Join Date: Mar 2024
Posts: 4
woocash_11 is on a distinguished road
Default

Hi vivka, thank you for this!

However I already tried something very similar and this one works exactly the same - it does change the parameter "exactly" to "at least", but it somehow changes the value of all rows to the value from the first row of first table in the document, and unfortunately it makes it unusable

I also tried asking AI, but apparently those I asked didn't work with VBA codes very well
Reply With Quote
  #4  
Old 03-17-2024, 05:26 AM
gmaxey gmaxey is offline Height of all rows of all tables set as "at least". Windows 10 Height of all rows of all tables set as "at least". Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub Tbls_Format_1()
Dim oRow As Row
Dim oTbl As Word.Table
  For Each oTbl In ActiveDocument.Tables
    For Each oRow In oTbl.Rows
       oRow.HeightRule = wdRowHeightAtLeast
    Next oRow
  Next oTbl
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 03-17-2024, 08:52 AM
woocash_11 woocash_11 is offline Height of all rows of all tables set as "at least". Windows 11 Height of all rows of all tables set as "at least". Office 2021
Novice
Height of all rows of all tables set as "at least".
 
Join Date: Mar 2024
Posts: 4
woocash_11 is on a distinguished road
Default

Thanks gmaxey.

Maybe this would work if the tables are basic. Unfortunatelly it doesn't work when there are tables with vertically merged cells.
Reply With Quote
  #6  
Old 03-17-2024, 09:05 AM
Italophile Italophile is online now Height of all rows of all tables set as "at least". Windows 11 Height of all rows of all tables set as "at least". Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Unless the height of the rows has already been set to "At Least", or "Exactly", there is no way to determine the current height of the row. Querying the row height in VBA will return a value of "Undefined".

You will need to decide what the minimum height should be, then modify the code in post #2 to set the Height property
Reply With Quote
  #7  
Old 03-17-2024, 09:35 AM
woocash_11 woocash_11 is offline Height of all rows of all tables set as "at least". Windows 11 Height of all rows of all tables set as "at least". Office 2021
Novice
Height of all rows of all tables set as "at least".
 
Join Date: Mar 2024
Posts: 4
woocash_11 is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
Unless the height of the rows has already been set to "At Least", or "Exactly", there is no way to determine the current height of the row. Querying the row height in VBA will return a value of "Undefined".

You will need to decide what the minimum height should be, then modify the code in post #2 to set the Height property
You know, the problem is I am OCR specialist and my software always defines table row height as "exactly". These heights vary depending on the table and I can't define the minimum height.

In my work computer there were the script on the outside platform that was doing this without any problems, so I thought it might be possible via VBA code. Apparently I was wrong
Reply With Quote
  #8  
Old 03-18-2024, 03:05 AM
Italophile Italophile is online now Height of all rows of all tables set as "at least". Windows 11 Height of all rows of all tables set as "at least". Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by woocash_11 View Post
In my work computer there were the script on the outside platform that was doing this without any problems, so I thought it might be possible via VBA code. Apparently I was wrong
It is possible via VBA code, but you need to answer the same question as in the UI - at least what?

This is a decision that is usually taken at the time of designing the document, not applied after the fact when you already have tables with content and merged cells.
Reply With Quote
  #9  
Old 03-18-2024, 03:07 PM
Guessed's Avatar
Guessed Guessed is offline Height of all rows of all tables set as "at least". Windows 10 Height of all rows of all tables set as "at least". Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this version
Code:
Sub TableRowAtLeast()
  Dim iSize As Long, aCell As Cell, aTbl As Table
  For Each aTbl In ActiveDocument.Tables
    For Each aCell In aTbl.Range.Cells
      If aCell.HeightRule = wdRowHeightExactly Then
        iSize = aCell.Height
        aCell.HeightRule = wdRowHeightAtLeast
        aCell.Height = iSize
      End If
    Next aCell
  Next aTbl
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Tags
height, table rows, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003: VBA "Function" causes "#VALUE!" errors after running "insert/delete row" custom macro Matt C Excel Programming 2 01-08-2022 06:03 AM
Height of all rows of all tables set as "at least". Help get rid of weird default "lines" or "table" look in document that has no tables or lines Tsavard Word 2 06-11-2018 09:08 AM
Height of all rows of all tables set as "at least". Macro to delete all rows with the word "Total" RandWald Excel Programming 4 11-28-2016 07:50 PM
Height of all rows of all tables set as "at least". Word Macro to find and delete rows that contain adjacent cells containing "." AlexanderJohnWilley Word VBA 7 11-08-2012 10:15 AM
Height of all rows of all tables set as "at least". How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:10 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