[英]VBA Change date format in textbox
I want to insert into textbox1 a date like "feb-2016" and to memorize in a variable "data" like i insert it. 我想在textbox1中插入一个日期,例如“ feb-2016”,并像我插入它一样存储在变量“ data”中。
Private Sub importa_buton_Click()
Dim data As Date
Dim luna As String
Dim anul As Integer
data = Analiza_Date.TextBox1.Value
TextBox1.Value = Format(data, "mmm-yyyy")
luna = month(data)
anul = year(data)
msgbox data
msgbox luna
msgbox anul
With the code above the output for msgbox data
is 01.02.2016 and i want to display like input "feb-2016" 上面的代码为msgbox data
的输出是01.02.2016,我想显示像输入“ feb-2016”
You can build up a string with the two functions MonthName
and Year
like this 您可以像这样用两个函数MonthName
和Year
建立一个字符串
Dim str As String
str = MonthName(date, TRUE) & "-" & Year(date)
where date
is your date. date
是您的日期。 If the second argument in MonthName
is TRUE
then the abbreviation and not the full month name is returned. 如果MonthName
的第二个参数为TRUE
则返回缩写而不是完整的月份名称。
Use the following code to save: 使用以下代码进行保存:
data As Date
, luna As String
and anul As Integer
data As Date
, anul As Integer
luna As String
, anul As Integer
Private Sub importa_buton_Click()
Dim data As Date
Dim luna As String
Dim anul As Integer
data = Analiza_Date.TextBox1.value
TextBox1.value = Format(data, "mmm-yyyy")
luna = Format(data, "mmm")
anul = Year(data)
MsgBox luna & "-" & anul
MsgBox luna
MsgBox anul
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.