文字列の日付から当月(年月)を表示する

<分類:値変換>
<使用例:文字列の日付(20190324)から年(2019)月(3)を表示する>
<プログラム例>

Sub 使用例()
   Dim date_moji As String
   Dim rtn_date As Date
   Dim rtn1 As String
   Dim rtn2 As String

   date_moji = "20190324"
   rtn_date = 共通_cov_date_9d(date_moji)
   rtn1 = (Year(rtn_date))
   rtn2 = (Month(rtn_date))

   MsgBox ("文字列の日付の年月は" & rtn1 & "年" & rtn2 & "月" & "です")

End Sub

Function 共通_cov_date_9d(p1 As String) As Date
    Dim d As Date
    d = Left(p1, 4) & "/" & Mid(p1, 5, 2) & "/" & Right(p1, 2)
    共通_cov_date_9d = (Format(d, "yyyy/mm/dd"))
End Function