VocExcel(単語帳) / VBA Tips
 
 [Key] エクセル / Excel / VBA /マクロ


<--- 戻る

フォームから日付の書式設定する

サンプルファイル






Private Sub ListBox1_Change()
Dim myFrmt

myFrmt = ListBox1.Text


Cells(1, "A").NumberFormatLocal = myFrmt 'セルに書式設定
Cells(1, "A") = Date


TextBox2.Text = ListBox1.Text
TextBox3.Text = Format(Date, myFrmt) 'テキストボックスに書式設定

End Sub




Private Sub UserForm_Initialize()

With ListBox1
.AddItem "yyyy年"
.AddItem "yy年"
.AddItem "ggg"
.AddItem "e"
.AddItem "ggge年"
.AddItem "gggee年"
.AddItem "m月"
.AddItem "mm月"
.AddItem "mmmm"
.AddItem "mmm"
.AddItem "d日"
.AddItem "dd日"
.AddItem "aaaa"
.AddItem "aaa"
.AddItem "(aaa)"
.AddItem "ddd"
.AddItem "dddd"
.AddItem "yyyy/mm/dd"
.AddItem "yy/m/d"
.AddItem "yy/mm/dd"
.AddItem "yyyy年m月d日"
.AddItem "yyyy年mm月dd日"
.AddItem "yy年mm月dd日"
.AddItem "ggge年m月d日"
.AddItem "gggee年mm月dd日"
.AddItem "m月d日"
.AddItem "mm月dd日"
End With

TextBox1.Text = Date
ListBox1.Text = "ggge年m月d日"

End Sub



--