본문 바로가기
VBA 라이브러리

MonthName 함수

2023. 8. 24.

MonthName 함수

지정된 월을 나타내는 문자열을 반환합니다.

Syntax
MonthName(month, [ abbreviate ])

month : 필수입니다. 해당 월의 숫자 지정입니다. 예를 들어 1월은 1, 2월은 2입니다.

abbreviate : 선택 사항입니다. 월 이름을 축약할지 여부를 나타내는 Boolean 값입니다. 생략하면 기본값은 False이며, 이는 월 이름이 축약되지 않음을 의미합니다.

예제

다음 코드는 abbreviate 매개변수를 기본값(False)으로 지정한 예제입니다.

Function GetMonthName(monthNumber As Integer, Optional abbreviate As Boolean = False) As String
    If abbreviate Then
        GetMonthName = monthName(monthNumber, True)
    Else
        GetMonthName = monthName(monthNumber)
    End If
End Function

Sub TestMonthNameModule()
    Dim monthNumber As Integer
    monthNumber = 8
    
    Dim monthName As String
    monthName = GetMonthName(monthNumber)
    
    Debug.Print monthNumber & "월은 " & monthName & "입니다."
End Sub

' Output
' 8월은 August입니다.

다음 코드는 abbreviate 매개변수를 True로 지정한 예제입니다.

Function GetMonthName(monthNumber As Integer, Optional abbreviate As Boolean = False) As String
    If abbreviate Then
        GetMonthName = monthName(monthNumber, True)
    Else
        GetMonthName = monthName(monthNumber)
    End If
End Function

Sub TestMonthNameModule()
    Dim monthNumber As Integer
    monthNumber = 8
    
    Dim monthName As String
    monthName = GetMonthName(monthNumber, True)
    
    Debug.Print monthNumber & "월은 " & monthName & "입니다."
End Sub

' Output
' 8월은 Aug입니다.

도움말 출처

MonthName function (Visual Basic for Applications)

Office VBA reference topic

learn.microsoft.com

'VBA 라이브러리' 카테고리의 다른 글

날짜 및 시간 관련 함수  (0) 2023.08.25
WeekdayName 함수  (0) 2023.08.24
InStrRev 함수  (0) 2023.08.24
InStr 함수  (0) 2023.08.23
FormatPercent 함수  (0) 2023.08.23