VBA-vba-初体验
wps 下载: WPS2019专业增强版带VBA_11.8.6.8810
技术文档:VBA-教程
背景:excel中日期字符串转日期时被当成int类型了,转换后的日期不是期望的值
eg: 19851017
目的:19851017 --> 1985-10-17
Function convert_to_date(str_data As String)
Debug.Print
Debug.Print
Debug.Print Now()
str_data = CStr(str_data)
If InStr(str_data, "-") Then
convert_to_date = str_data
Else
str_year = Mid(str_data, 1, 4)
str_month = Mid(str_data, 5, 2)
str_day = Mid(str_data, 7)
str_day = str_year & "-" & str_month & "-" & str_day
convert_to_date = str_day
End If
End Function