Excel表单日期格式

时间:2016-01-28 22:54:15

标签: excel vba excel-vba

我有一个表单文本框,以这种格式 Dec-15 输入月份和年份,但它实际上会返回 value 15/12/2016 VBA代码。

我怎样才能成功?01/12/2015?

sMonthYear = Trim(Form.txtMonthYear.Value)

报告标题= 12月15日

Sheets("Report").Cells(2, 2).Value = "" & sMonthYear & ""

找到Folder = 2015

sFolderYear = Year(sMonthYear)
strSavePath = sFilePath + sFolderYear + "\"

档案名称= Dec-15

sFileName = sMonthYear
wbDest.SaveAs strSavePath & sFileName & ".xls"

由于

1 个答案:

答案 0 :(得分:0)

试试这个......

Sheets("Sheet1").Cells(2, 2).Value = "01" & "" & sMonthYear & ""

或格式化单元格

Option Explicit
Sub DateFormat()
    Dim sMonthYear As String

    sMonthYear = "Dec-15"

    Sheets("Sheet1").Cells(2, 2).NumberFormat = "DD/MM/YYYY"
    Sheets("Sheet1").Cells(2, 2).Value = "01" & "" & sMonthYear & ""

End Sub