Thread: [Solved] Macro Help
View Single Post
 
Old 02-01-2013, 06:54 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
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

Hi kaurp,

Try the following (it's a slightly enhanced version of your's and handles the 'Notes:' issue).

Regarding:
Quote:
I need it to find a certain word within a table in word, select that row and change the height.
Your code looks for 'California', but then only sets the height rule - which doesn't of itself change the height. I've modified the code to make the height exactly 0.75in.

Regarding:
Quote:
If a certain page has a word in it but no table, delete that page.
Pages are a rubbery concept in Word, as their layout and content is largely determined by the current print driver; what's empty with one printer may have content when another printer is used. Unless you're using manual page breaks and/or 'next page' section breaks to define the pages, you'll need a different approach.

Code:
Public Sub ACF()
Application.ScreenUpdating = False
Dim i As Long, j As Long, Rng As Range
With ActiveDocument
     'Updates all tables of contents
    For i = 1 To .TablesOfContents.Count
      .TablesOfContents(i).Update
    Next i
     'Deletes last page if it's blank
    While .Range.Characters.Last.Previous = vbCr Or .Range.Characters.Last.Previous = Chr(12)
        .Range.Characters.Last.Previous.Delete
    Wend
    For i = .Tables.Count To 1 Step -1
        With .Tables(i)
            For j = .Rows.Count To 1 Step -1
                With .Rows(j)
                     'Deletes row if empty
                    If Len(.Range.Text) = (.Cells.Count * 2 + 2) Then
                        .Delete
                    Else
                         'Sets State row height
                        If .Cells.Count > 1 Then
                            Set Rng = .Cells(1).Range
                            If InStr(Rng, "California") > 0 Then
                                .HeightRule = wdRowHeightExactly
                                .Height = InchesToPoints(0.75)
                            End If
                            If Split(Rng.Text, " ")(0) = "Notes:" Then
                                .Range.Tables(1).ConvertToText
                                Exit For
                            End If
                        End If
                    End If
                End With
            Next j
        End With
    Next i
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote