Formatting table code is not working in Macbook, it always show i haven't selected table

15 Views Asked by At

My code is working in windows and its not working in the Mac machine can anyone help me with the code error in this

Sub Singleheadertableformatting() Dim lngRow As Long Dim lngCol As Long Dim lngFont As Long Dim objTable As Table Dim oshp As Shape

On Error GoTo err1
Set objTable = ActiveWindow.Selection.ShapeRange.Table
Set oshp = ActiveWindow.Selection.ShapeRange(1)

For lngRow = 1 To 1
    For lngCol = 1 To 1
        If objTable.Rows(lngRow).Cells(lngCol).Selected Then
            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame.TextRange.Font
                lngFont = .Size
            End With
        End If
    Next
Next

For lngRow = 1 To objTable.Rows.Count
    For lngCol = 1 To objTable.Columns.Count
        If objTable.Rows(lngRow).Cells(lngCol).Selected Then
            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame.TextRange.ParagraphFormat
                .LineRuleWithin = msoTrue
                .SpaceWithin = 1
            End With

            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame.TextRange.ParagraphFormat.Bullet.Font
                .Color = RGB(0, 0, 0)
            End With

            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame.TextRange.Font
                .Size = lngFont
                .Name = "Calibri"
                .Bold = False
                .Italic = False
                .Shadow = False
                .Color = RGB(0, 0, 0)
            End With

            With objTable.Rows(lngRow).Cells(lngCol).Shape
                .Fill.Visible = msoTrue
                .Fill.ForeColor.RGB = RGB(255, 255, 255)
                .Fill.Transparency = 0
            End With

            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame
                .MarginLeft = 6
                .MarginRight = 6
                .MarginTop = 3
                .MarginBottom = 3
                .VerticalAnchor = msoAnchorTop
                .TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignLeft
            End With
        End If
    Next
Next

For lngRow = 1 To 1
    For lngCol = 1 To objTable.Columns.Count
        If objTable.Rows(lngRow).Cells(lngCol).Selected Then
            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame
                .VerticalAnchor = msoAnchorMiddle
            End With

            With objTable.Rows(lngRow).Cells(lngCol).Shape.TextFrame.TextRange.Font
                .Size = lngFont
                .Name = "Calibri"
                .Bold = True
                .Italic = False
                .Color = RGB(134, 188, 37)
            End With

            With objTable.Rows(lngRow).Cells(lngCol)
                .Borders(ppBorderTop).Transparency = 0
                .Borders(ppBorderTop).ForeColor.RGB = RGB(134, 188, 37)
                .Borders(ppBorderTop).Weight = 3
            End With
        End If
    Next
Next

For lngRow = 1 To objTable.Rows.Count
    For lngCol = 1 To objTable.Columns.Count
        If objTable.Rows(lngRow).Cells(lngCol).Selected Then
            With objTable.Rows(lngRow).Cells(lngCol)
                .Borders(ppBorderBottom).Transparency = 0
                .Borders(ppBorderBottom).ForeColor.RGB = RGB(255, 255, 255)
                .Borders(ppBorderBottom).Weight = 0.5
                .Borders(ppBorderBottom).Transparency = 0
                .Borders(ppBorderBottom).ForeColor.RGB = RGB(187, 188, 188)
                .Borders(ppBorderBottom).Weight = 0.5
            End With
        End If
    Next
Next

MsgBox "Table Formatting Completed Successfully!", vbInformation

Normalexit: Exit Sub

err1: MsgBox "You haven't selected any table" Resume Normalexit End Sub

0

There are 0 best solutions below