###前提・実現したいこと
VBAでフォームが最初に立ち上がるシステムを作っています。
フォームを×ボタンで閉じると以下のようなエラーメッセージが発生しました。
デバックを押すと下記のようなメッセージが現れ、該当コードが黄色で反転されています。
以前にもエクセルを立ち上げたときに、ユーザーフォームが表示されるシステムを作りましたが、その時は今回のようなエラーメッセージは掃かれませんでした。
分かる方、ご教示願います。
UserFormのコードを追記いたします。
Private Sub ComboBox1_Change() End Sub Private Sub CommandButton1_Click() Dim i For i = 10 To 60 Step 10 ComboBox1.AddItem i & "分" Next End Sub Private Sub CommandButton2_Click() Cells.Select Selection.ColumnWidth = 2 If Cells(1, 1) = "" Then Worksheets("Task").Cells(1, 1).Value = TextBox1.Value Columns("A:E").AutoFit If ComboBox1.Text = "10分" Then Cells(1, 2).Interior.ColorIndex = 3 Cells(1, 2).Value = "□" ElseIf ComboBox1.Text = "20分" Then Range(Cells(1, 2), Cells(1, 3)).Interior.ColorIndex = 3 Range(Cells(1, 2), Cells(1, 3)).Value = "□" ElseIf ComboBox1.Text = "30分" Then Range(Cells(1, 2), Cells(1, 4)).Interior.ColorIndex = 3 Range(Cells(1, 2), Cells(1, 4)).Value = "□" ElseIf ComboBox1.Text = "40分" Then Range(Cells(1, 2), Cells(1, 5)).Interior.ColorIndex = 3 Range(Cells(1, 2), Cells(1, 5)).Value = "□" ElseIf ComboBox1.Text = "50分" Then Range(Cells(1, 2), Cells(1, 6)).Interior.ColorIndex = 3 Range(Cells(1, 2), Cells(1, 6)).Value = "□" ElseIf ComboBox1.Text = "60分" Then Range(Cells(1, 2), Cells(1, 7)).Interior.ColorIndex = 3 Range(Cells(1, 2), Cells(1, 7)).Value = "□" End If Else 'MsgBox Maxcol n = Cells(Rows.Count, 1).End(xlUp).Row + 1 'MsgBox n 'With Range("A" & n - 1).SpecialCells(xlLastCell) With Cells(n - 1, Columns.Count).End(xlToLeft).Column 'maxrow = .Row l = Cells(n - 1, Columns.Count).End(xlToLeft).Column + 1 End With 'MsgBox l '最終行を求めてしまっている↓ ''m = Range("A" & n - 1).End(xlToRight).Column + 1 'm = Range("A" & Columns.Count).End(xlToLeft).Column + 1 'm = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 1) ''MsgBox m Worksheets("Task").Cells(n, 1).Value = TextBox1.Value Columns("A:E").AutoFit If ComboBox1.Text = "10分" Then Cells(n, l).Interior.ColorIndex = 3 'Range(n, m).Value = "□" Cells(n, l).Value = "□" ElseIf ComboBox1.Text = "20分" Then Range(Cells(n, l), Cells(n, l + 1)).Interior.ColorIndex = 3 Range(Cells(n, l), Cells(n, l + 1)).Value = "□" ElseIf ComboBox1.Text = "30分" Then Range(Cells(n, l), Cells(n, l + 2)).Interior.ColorIndex = 3 Range(Cells(n, l), Cells(n, l + 2)).Value = "□" ElseIf ComboBox1.Text = "40分" Then Range(Cells(n, l), Cells(n, l + 3)).Interior.ColorIndex = 3 Range(Cells(n, l), Cells(n, l + 3)).Value = "□" ElseIf ComboBox1.Text = "50分" Then Range(Cells(n, l), Cells(n, l + 4)).Interior.ColorIndex = 3 Range(Cells(n, l), Cells(n, l + 4)).Value = "□" ElseIf ComboBox1.Text = "60分" Then Range(Cells(n, l), Cells(n, l + 5)).Interior.ColorIndex = 3 Range(Cells(n, l), Cells(n, l + 5)).Value = "□" End If End If End Sub Private Sub Label2_Click() End Sub Private Sub TextBox1_Change() End Sub Private Sub UserForm_Click() End Sub Private Sub UserForm_Initialize() UserForm1.Show End Sub
そのExcelには複数のアドインがインストールされているかを教えて下さい。また、複数のアドインが読み込まれている場合、いずれかのアドインの起動時にシートオブジェクトなどを参照しているものがあるかを教えて下さい。
複数のアドインはインストールされていません。
すいません、追加で教えて下さい。当該事象が発生しているマクロはアドイン(xlam)ファイルですか。それともマクロブック(xlsm)ですか。
マクロブック(xlsm)になります。
UserForm1のソースコードを拝見することは可能でしょうか。あと、VBEの設定にて、ツール(T)-オプション(O) にある全般タブのエラートラップの設定をクラスモジュールで中断(R)にして再度マクロを実行した時に黄色くなるコード位置も教えて頂きたいです。
userform1の中身も出していただけますか?
baseballyama様>設定をした後に黄色くなるコードは画像にある通り「UserForm1.Show」です。
slash様>質問にuserform1の中身を追加しました。
回答1件
あなたの回答
tips
プレビュー