Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Dec 2015
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word 2007 Row Height Macro

    I have many Word files that I need to update and hoping I can do this with a macro.

    Currently the doc has a table with 14 rows that are set to exact size as follows
    33mm, 5mm, 6.5mm, 33mm, 5mm, 6.5mm, 33mm, 5mm, 6.5mm, 33mm, 5mm, 6.5mm, 33mm, 5mm

    But I need to change the heights to this
    32mm, 6mm, 6.5mm, 32mm, 6mm, 6.5mm, 32mm, 6mm, 6.5mm, 32mm, 6mm, 6.5mm, 32mm, 6mm

    These are for labels and the current row sizes are not matching up correctly. I tried to adjust them by recording a macro however when i run the macro it just sets all the rows to 32mm.

    Can anyone help?

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quxote,

    Welcome to the Lounge as a new poster.

    This should do the trick.
    Code:
    Option Explicit
    
    Sub Multi_RowHeight()
    
       Dim vRHeight  As Variant
       Dim lRowCntr  As Long
       Dim lRowOfs   As Long   'Starting row
    
       vRHeight = Array(32, 6, 6.5, 32, 6, 6.5, 32, 6, 6.5, 32, 6, 6.5, 32, 6)
       
       lRowOfs = 1    '*** Set Starting Row Here ***
       
       For lRowCntr = 0 To 13
          Rows(lRowCntr + lRowOfs).RowHeight = vRHeight(lRowCntr)
       Next lRowCntr
       
    End Sub   'Multi_RowHeight
    Make sure you have your Ruler is set to millimeters in File->Options->Advanced->Display->Ruler Units.


    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    New Lounger
    Join Date
    Dec 2015
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much for the welcome and the help.

    When I run the macro i get Compile Error: Sub or Function Not defined
    And the word Rows is highlighted in this row
    Rows(lRowCntr + lRowOfs).RowHeight = vRHeight(lRowCntr)

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quxote,

    My bad! That's an Excel Macro and you're working in Word. Sorry, when I read the post I forgot which forum it was posted to.

    I'll try to figure it out in Word and get back to you if some of the Word Gurus don't beat me to it.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Quxote,

    Ok, here's a version for MS Word.
    Code:
    Option Explicit
    
    Sub Multi_RowHeights()
      
       Dim vRHeight  As Variant
       Dim lRowCntr  As Long
       Dim lRowOfs   As Long   'Starting row
    
       Selection.WholeStory
      
       vRHeight = Array(32, 6, 6.5, 32, 6, 6.5, 32, 6, 6.5, 32, 6, 6.5, 32, 6)
       
       lRowOfs = 1    '*** Set Starting Row Here ***
       
       For lRowCntr = 0 To 13
          Selection.Tables(1).Rows(lRowCntr + lRowOfs).Height = MillimetersToPoints(vRHeight(lRowCntr))
       Next lRowCntr
       
    End Sub   'Multi_RowHeight
    Note: As coded the macro will always change the first table in the document.

    You could make this work on other than the first table by changing the table number in this line:
    Code:
    Selection.Tables(1).Rows(lRowCntr + lRowOfs).Height = MillimetersToPoints(vRHeight(lRowCntr))
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    New Lounger
    Join Date
    Dec 2015
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much for your help!!

Posting Permissions

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