View Single Post
 
Old 09-07-2022, 12:09 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 200
Cendrinne is on a distinguished road
Default Help with a script for IF with Cell Border LineWidth less than X, then put Y

Hello Pros,
Again, I'm stuck on this script I found on the web, I've just modified it to my needs.
It Works, BUT, it has No Dim, so being on Option Explicit, doesn't work.
If I remove ''Option Explicit'', it's slow for a few tables on a couple of pages as a test, yet it checks every cell, so normal it's slow, but it does Work.

I'm trying to fix the macro to have Option Explicit, along with Dim, etc. Reason, because all my scripts are for Option Explicit.
Whatever I try, it either does Nothing, or I get an error message.

I hate to give up, so PLEASE, could you help me.

Cause on tables in a word document, people don't open the screen big enough, and they assume, a 0.75 pt, could be a 0.50 pt, so on same line or row, I see both borders.

It's very long when you have to verify over 50 tables in a document to fix them.

On that same web page, someone created a macro with Dim, but it add's borders from the enum (-6 to -1), from these data: WdBorderType Enum (Microsoft.Office.Interop.Word) | Microsoft Docs

Code:
Sub FixCellBorders()
'Found on Web https://wordribbon.tips.net/T013081_Setting_a_Default_Table_Border_Width
   On Error Resume Next
    ' Work through all tables in document
    For Each objTable In ActiveDocument.Tables
        ' Work through all cells in each table
        For Each objCell In objTable.Range.Cells
            ' Work through all borders in each cell
            For Each objBorder In objCell.Borders
                ' Check if line weight is less than 1.00 pt
                If objBorder.LineWidth = wdLineWidth050pt _
                  Or objBorder.LineWidth = wdLineWidth075pt Then
                    ' too thin, change it
                    objBorder.LineWidth = wdLineWidth100pt
                End If
            Next objBorder
        Next objCell
    Next objTable
End Sub
I'm very clueless, so any insights would be so appreciative

Cendrinne
Reply With Quote