└ Sctipt-text

Sctipt-text #

What is it? #

Useful functions for handling text.


Text arrange #

Adjusts letter spacing of Malgun Gothic font to 0.3.


zeromargin #

Sets margins of text boxes or shapes to zero.

Sub textMarginZero()

    On Error GoTo Err_Check ' 에러 발생 시 Err_Check로 이동

    Dim shp As shape
    Dim activeshape As shape
    Dim myt As Table
    Dim z As Double
    Dim dtb As Double
    Dim dlr As Double

    ' 선택된 도형이 있는지 확인
    If ActiveWindow.Selection.Type = ppSelectionShapes Then
        For Each shp In ActiveWindow.Selection.ShapeRange
            Set activeshape = shp
            Exit For
        Next shp
    Else
        MsgBox "There is no shape currently selected!", vbExclamation, "No Shape Found"
        Exit Sub
    End If

    z = 0
    dlr = ConvertCmToPoint(0.13)
    dtb = ConvertCmToPoint(0.25)

    ' 메시지 박스에서 사용자가 선택한 값을 처리
    If MsgBox("To Zero : Yes, To Default : No", vbYesNo) = vbYes Then

        If shp.HasTable Then
            Set myt = shp.Table

            cnum = myt.Columns.Count
            rnum = myt.Rows.Count

            ' 테이블 내의 셀에 마진 값 적용
            With myt
                For c = 1 To cnum
                    For r = 1 To rnum
                        .cell(r, c).shape.TextFrame2.MarginTop = z
                        .cell(r, c).shape.TextFrame2.MarginBottom = z
                        .cell(r, c).shape.TextFrame2.MarginLeft = z
                        .cell(r, c).shape.TextFrame2.MarginRight = z
                        .cell(r, c).shape.TextFrame2.VerticalAnchor = msoAnchorMiddle
                    Next r
                Next c
            End With
        Else
            ' 테이블이 아닌 경우 일반 텍스트 상자의 마진 값 적용
            With shp.TextFrame2
                .MarginTop = z
                .MarginBottom = z
                .MarginLeft = z
                .MarginRight = z
                .VerticalAnchor = msoAnchorMiddle
            End With
        End If

    Else
        If shp.HasTable Then
            Set myt = shp.Table

            cnum = myt.Columns.Count
            rnum = myt.Rows.Count

            ' 테이블 내의 셀에 기본 마진 값 적용
            With myt
                For c = 1 To cnum
                    For r = 1 To rnum
                        .cell(r, c).shape.TextFrame2.MarginTop = dtb
                        .cell(r, c).shape.TextFrame2.MarginBottom = dtb
                        .cell(r, c).shape.TextFrame2.MarginLeft = dlr
                        .cell(r, c).shape.TextFrame2.MarginRight = dlr
                        .cell(r, c).shape.TextFrame2.VerticalAnchor = msoAnchorMiddle
                    Next r
                Next c
            End With
        Else
            ' 테이블이 아닌 경우 일반 텍스트 상자의 기본 마진 값 적용
            With shp.TextFrame2
                .MarginTop = dtb
                .MarginBottom = dtb
                .MarginLeft = dlr
                .MarginRight = dlr
                .VerticalAnchor = msoAnchorMiddle
            End With
        End If
    End If

    Exit Sub

Err_Check:
    If Err.Number <> 0 Then
        MsgBox "오류번호 : " & Err.Number & vbCr & _
        "오류내용 : " & Err.Description, vbCritical, "오류 발생"
    End If

End Sub


Function ConvertPointToCm(ByVal pnt As Double) As Double
    ConvertPointToCm = pnt * 0.03527778
End Function

Function ConvertCmToPoint(ByVal cm As Double) As Double
    ConvertCmToPoint = cm * 28.34646
End Function