sTxt = InputBox("Bitte Eingabe tätigen:")
Abbildung - VBA-InputboxsTxt = Application.InputBox("Bitte Eingabe tätigen:")
Abbildung - Excel-Inputbox
Sub Aufruf()
Dim sTxt As String
sTxt = InputBox("Eingabe:")
If sTxt = "" Then Exit Sub
MsgBox sTxt
End Sub
Sub SetPrompt()
Dim sTxt As String, sPrompt As String
sPrompt = "Nutzen Sie bitte folgende Syntax:" & vbLf & _
" 'dd.mm.yyyy' oder" & vbLf & _
" 'dd/mm/yyyy' oder" & vbLf & _
" 'dd-mm-yyyy':"
sTxt = InputBox(prompt:=sPrompt)
On Error GoTo ERRORHANDLER
MsgBox CDate(sTxt)
Exit Sub
ERRORHANDLER:
MsgBox "Kein gültiges Datumsformat!"
End Sub
So siehts aus:
Sub SetTitle()
Dim sTxt As String, sTitle As String
sTitle = Application.UserName & " says:"
sTxt = InputBox(prompt:="Eingabe:", Title:=sTitle)
If sTxt = "" Then Exit Sub
MsgBox sTxt
End Sub
So siehts aus:
Sub SetDefault()
Dim sTxt As String, sPrompt As String, sDefault As String
sPrompt = "Eingangsdatum eingeben:"
sDefault = Format(Date - 3, "dd.mm.yyyy")
sTxt = InputBox(prompt:=sPrompt, Default:=sDefault)
On Error GoTo ERRORHANDLER
MsgBox CDate(sTxt)
Exit Sub
ERRORHANDLER:
MsgBox "Kein gültiges Datumsformat!"
End Sub
So siehts aus:
Sub SelDefault()
Dim sTxt As String, sPrompt As String, sDefault As String
sPrompt = "Eingangsdatum eingeben:"
sDefault = Format(Date - 3, "dd.mm.yyyy")
SendKeys "{home}{right 3}+{right 2}"
sTxt = InputBox(prompt:=sPrompt, Default:=sDefault)
On Error GoTo ERRORHANDLER
MsgBox CDate(sTxt)
Exit Sub
ERRORHANDLER:
MsgBox "Kein gültiges Datumsformat!"
End Sub
So siehts aus:
Sub InputBoxPositionA()
Dim sTxt As String
sTxt = InputBox(prompt:="Eingabe:", xpos:=1000, ypos:=1000)
End Sub
So siehts aus:
Sub InputBoxPositionB()
Dim rng As Range
Dim iLeft As Integer, iTop As Integer
Dim sTxt As String
Set rng = Range("B3")
iLeft = rng.Left + 23
iTop = rng.Top + 16
sTxt = Application.InputBox( _
prompt:="Eingabe:", Left:=iLeft, Top:=iTop)
End Sub
So siehts aus:
Sub CallHelpA()
Dim sTxt As String, sFile As String
sFile = ThisWorkbook.Path & "\Kontext.chm"
If Dir(sFile) = "" Then
Beep
MsgBox "Hilfedatei existiert nicht!"
Exit Sub
End If
sTxt = InputBox( _
prompt:="Eingabe:", _
HelpFile:=sFile, _
Context:="1001")
End Sub
So siehts aus:
Sub CallHelpB()
Dim sTxt As String, sFile As String
sFile = ThisWorkbook.Path & "\Kontext.chm"
If Dir(sFile) = "" Then
Beep
MsgBox "Hilfedatei existiert nicht!"
Exit Sub
End If
sTxt = Application.InputBox( _
prompt:="Eingabe:", _
HelpFile:=sFile, _
HelpContextID:="1001")
End Sub
So siehts aus:Wert | Bedeutung |
---|---|
0 | Formel |
1 | Zahl |
2 | Text (Zeichenfolge) |
4 | Logischer Wert (True oder False) |
8 | Zellbezug, z. B. ein Range-Objekt |
16 | Fehlerwert, z. B. #N/A |
64 | Wertematrix |
Sub AufrufA()
Dim vInput As Variant
vInput = Application.InputBox( _
prompt:="Bitte Eingabe tätigen:", _
Title:="Bezüge oder Zahlen", _
Type:=9)
MsgBox vInput
End Sub
Wird weder ein Zellbezug noch eine Zahl eingetragen, wird die Eingabe nicht akzeptiert:
Sub Aufruf()
Dim rng As Range
Set rng = Application.InputBox( _
prompt:="Bitte Eingabe tätigen:", _
Title:="Bezug vorgeben:", _
Type:=8)
rng.NumberFormat = "00000"
End Sub
Wir der InputBox-Wert nicht als Range-Objekt deklariert und mit Set übergeben, wird nicht das
Range-Objekt, sondern der Wert der ersten Zelle des deklarierten Bereiches zurückgegeben.
Sub AufrufB()
Dim rng As Range
On Error GoTo ERRORHANDLER
Set rng = Application.InputBox( _
prompt:="Bitte Eingabe tätigen:", _
Title:="Bezug vorgeben:", _
Type:=8)
MsgBox WorksheetFunction.Sum(rng)
ERRORHANDLER:
End Sub