InputBoxの例

例題

インプットボックスから入力されて始点と終点を使って任意の場所に表を作成し、インプットボックスを用いて指定した任意の場所に表のデータを入力する。

例文1

Dim StartP, EndP, inputP, inputT As Variant
Dim inFlug As Integer

Sub example4()
Label1:
  '表を作成する
   StartP = Application.InputBox(prompt:= _
   "始点のセル番号を入力して下さい。", _
   Title:="表の罫線作成ポイント(始点)")
   If StartP = False Then Exit Sub    
   EndP = Application.InputBox(prompt:= _
   "終点のセル番号を入力して下さい。", _
   Title:="表の罫線作成ポイント(終点)")
   If EndP = False Then Exit Sub
   
   On Error GoTo ERR1 ' エラー処理
   If StartP <> "" And EndP <> "" Then
       With Sheet1.Range(StartP, EndP).Borders
       .LineStyle = xlContinuous
       .ColorIndex = xlAutomatic
       .Weight = xlThin
       End With
       
       inFlug = MsgBox("次の処理を行います", vbYesNo)
       While inFlug = 6 ' NOを押すまで繰り返します
           Call inputText
           inFlug = MsgBox("処理を継続しますか?", vbYesNo)
       Wend
   Else
       MsgBox "始点または終点が空白です"
   End If
   Exit Sub

ERR1:
  MsgBox "実行時エラー:" & "始点または終点の値が不正です"
   GoTo Label1
End Sub

Sub inputText()
Label2:
  '入力する
   inputP = Application.InputBox(prompt:= _
   "入力開始位置のセル番号を入力して下さい。", _
   Title:="入力位置(始点)")
   If inputP = False Then Exit Sub
   
   inputT = Application.InputBox(prompt:= _
   "入力内容を入力してください。", _
   Title:="入力内容")
   If inputT = False Then Exit Sub
   
   On Error GoTo ERR2 ' エラー処理
   Range(inputP) = inputT ' 入力内容を書き込む
   Exit Sub
   
ERR2:
  MsgBox "実行時エラー:" & "テキスト入力位置の指定が不正です"
   GoTo Label2
End Sub



  • 最終更新:2011-03-31 18:22:52

このWIKIを編集するにはパスワード入力が必要です

認証パスワード