Consulting

Results 1 to 3 of 3

Thread: Macro search text BOLD UPPERCASE if within table row and apply style Word

  1. #1
    VBAX Regular
    Joined
    Jul 2012
    Posts
    29
    Location

    Macro search text BOLD UPPERCASE if within table row and apply style Word

    Hi, attach document.

    Would like to search document using VBA to change BOLD UPPERCASE heading that only appears "within a table row (always shaded)" and apply heading style Heading UCPR.

    The doc downloads in Normal usually.

    Many thanks for any assistance.

    Janine
    Attached Files Attached Files

  2. #2
    The following will work in your document.
    Sub Macro1()
    Const sPwd As String = ""    'the form password if any
    Dim oTable As Table
    Dim oCell As Cell
    Dim oRng As Range
    Dim lProtect As Long
        lProtect = ActiveDocument.ProtectionType
        If Not ActiveDocument.ProtectionType = wdNoProtection Then
            ActiveDocument.Unprotect Password:=sPwd
        End If
        For Each oTable In ActiveDocument.Tables
            For Each oCell In oTable.Range.Cells
                Set oRng = oCell.Range
                oRng.End = oRng.End - 1
                If oRng.Case = wdUpperCase And oRng.Font.Bold = True Then
                    oRng.Style = "Heading_UCPR"
                End If
            Next oCell
        Next oTable
        ActiveDocument.Protect Type:=lProtect, NoReset:=True, Password:=sPwd
        Set oTable = Nothing
        Set oCell = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Jul 2012
    Posts
    29
    Location
    Many thanks Graham - perfect.

Posting Permissions

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