Results 1 to 4 of 4

Thread: Help with Macro

  1. #1
    New Lounger
    Join Date
    Dec 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Macro

    Please Help me! I need macro for word to delete all Blank Line in all Cells of all Tables in A document.
    I ever have used simple commandlind:
    with secletion.find
    Text = "^p^p"
    Replacement Text ="^p",
    ...........
    But the last entirerow of cells have Blank line, not be delete by that command!
    Can you help me! Pleaae, thanks

  2. #2
    New Lounger
    Join Date
    Dec 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Who Help me!
    My theory: In the word document have alots of range as AAAA and BBBB.
    In Headings, there are 2 heading start with AAAA and other paragraphs heading is started by BBBB.
    I need Link anchor from all "AAAA normal text" to Paragrahp heading started by AAAA.
    Please help me

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    These will not delete table rows.
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The following code will delete all blank rows (except for those with vertically merged cells) in all tables in the active document, including those containing empty formfields.
    Code:
    Sub DelBlankRows()
    Application.ScreenUpdating = False
    Dim Pwd As String, pState As Variant, bFit As Boolean, i As Long, j As Long
    With ActiveDocument
      pState = False
      If .ProtectionType <> wdNoProtection Then
        Pwd = InputBox("Please enter the Password", "Password")
        pState = .ProtectionType
        .Unprotect Pwd
      End If
      For i = .Tables.Count To 1 Step -1
        With .Tables(i)
          bFit = .AllowAutoFit
          .AllowAutoFit = False
          For j = .Rows.Count To 1 Step -1
            On Error Resume Next 'skip vertically merged cells
            With .Rows(j)
              'ChrW(8194) is the formfield space character. Trim erases any other spaces
              If Trim(Replace(Replace(Replace(.Range.Text, Chr(13) & Chr(7), ""), _
                ChrW(8194), ""), Chr(160), "")) = "" Then .Delete
            End With
            On Error GoTo 0
          Next
          On Error Resume Next 'skip deleted tables
          .AllowAutoFit = bFit
          On Error GoTo 0
        End With
      Next
      If pState <> wdNoProtection Then .Protect Type:=pState, NoReset:=True, Password:=Pwd
    End With
    Application.ScreenUpdating = True
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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