Private Sub CommandButton49_Click() 'ユーザーフォームのハンドルを取得 'https://excel-excel.com/tips/vba_69.html Dim hwnd As Long If buttonOn = False Then hwnd = FindWindow(vbNullString, Me.Caption) hTargetDC = GetDC(hwnd) If hTargetDC = 0 Then Cells(1, 3).Value = "失敗しました。" Else Cells(1, 3).Value = hTargetDC End If Cells(1, 1) = hwnd 'https://tsware.jp/tips/tips_174.htm Dim strWindowText As String * 128 'キャプションを受け取る変数 Dim lngRet As Long 'API関数を呼び出します lngRet = GetWindowText(hwnd, strWindowText, Len(strWindowText)) '引数の後続の Null を取り除いて表示します Cells(1, 2) = Left$(strWindowText, InStr(strWindowText, vbNullChar) - 1) Call BeginSubClass(hwnd) buttonOn = True ' CommandButton1.Enabled = False 'http://www.officetanaka.net/excel/vba/tips/tips136.htm sy = UserForm1.Top sx = UserForm1.Left Else End If End Sub Private Sub CommandButton50_Click() Dim hwnd As Long hwnd = FindWindow(vbNullString, Me.Caption) Call EndSubClass(hwnd) buttonOn = False End Sub