Thread: [Solved] Macro Help
View Single Post
 
Old 01-30-2013, 12:34 PM
kaurp kaurp is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jan 2013
Posts: 3
kaurp is on a distinguished road
Default Macro Help

Hi, I'm trying to write a macro that does a few different things. I have somethings working and others I'm having trouble with.

I need it to find a certain word within a table in word, select that row and change the height.

If the first row of a table is blank, delete it.

Convert a table to text if it starts with the word "Notes:" in the first cell.

If a certain page has a word in it but no table, delete that page.

There are some other things it needs to do that I already have working and here is what I have:
Code:
Public Sub ACF() 
     'Updates table of content
    ActiveDocument.TablesOfContents(1).Update 
     
     'Deletes last page if it's blank
    Dim i As Long 
    For i = ActiveDocument.Paragraphs.Count To 1 Step -1 
        If Asc(ActiveDocument.Paragraphs(i).Range.Text) = 12 Then 
            ActiveDocument.Paragraphs(i).Range.Delete 
            Exit For 
        End If 
        If Len(ActiveDocument.Paragraphs(i).Range.Text) > 1 Then 
            Exit For 
        End If 
    Next i 
     
     'Deletes table if they are blank
    Application.ScreenUpdating = False 
    Dim Tbl As Table, cel As Cell, n As Long, fEmpty As Boolean 
    With ActiveDocument 
        For Each Tbl In .Tables 
            n = Tbl.Rows.Count 
            For i = n To 1 Step -1 
                fEmpty = True 
                For Each cel In Tbl.Rows(i).Cells 
                    If Len(cel.Range.Text) > 2 Then 
                        fEmpty = False 
                        Exit For 
                    End If 
                Next cel 
                If fEmpty = True Then Tbl.Rows(i).Delete 
            Next i 
        Next Tbl 
    End With 
    Set cel = Nothing: Set Tbl = Nothing 
    Application.ScreenUpdating = True 
     
     'State table row heights
    Dim oTbl As Table, x As Integer, z As Integer 
    With oTbl 
        For i = .Rows.Count To 1 Step -1 
            With .Rows(i) 
                If .Cells.Count > 1 Then 
                    Set Rng = .Cells(1, 1).Range 
                    If FindText(Rng, "California") = True Then .HeightRule = wdRowHeightAtLeast 
                     
                End If 
            End With 
        Next 
    End With 
     
End Sub

Last edited by macropod; 02-01-2013 at 06:14 PM. Reason: Added code tags & formatting
Reply With Quote