0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【VBA】自動ユーザーフォーム起動

Last updated at Posted at 2019-05-22

##説明
・エクセルファイルを起動したらユーザーフォームのみが表示される
・ユーザーフォームを「閉じる」ボタンで閉じたらエクセルファイルも閉じる

###標準モジュール

Sub Auto_Open()
    UserForm1.Show
End Sub

###UserForm1

Private Sub CommandButton1_Click()
    Dim wb As Workbook
    Set wb = ActiveWorkbook
    Call wb.Close(True)  ' 変更を保存して閉じる
End Sub

Private Sub TextBox1_Change()
    Call CalculateTime
End Sub

Private Sub TextBox2_Change()
    Call CalculateTime
End Sub

Private Sub TextBox3_Change()
    Call CalculateTime
End Sub

Private Sub TextBox4_Change()
    Call CalculateTime
End Sub

Private Sub UserForm_Initialize()
    Application.Visible = False
End Sub

Private Sub UserForm_Terminate()
    Application.Visible = True
End Sub

Private Sub CalculateTime()
    Dim tm As Long
    With UserForm1
        tm = (Val(.TextBox1.Value) - 18) * 60 + (Val(.TextBox2.Value) - 15)
        .TextBox3.Value = Int(tm / 60)
        .TextBox4.Value = tm Mod 60
    End With
End Sub

###画像1
無題.png

###画像2
無題2.png

##参考サイト
後日記載

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?