input框中的取消button在Excel单元格中的值没有改变
我正在运行一个VBA,我有取消button的问题,我不想改变单元格中的值,如果取消button按下或退出button。 如何进行?
Private Sub Workbook_Open() Sheets("Start").Range("B1").Value = Application.InputBox(Prompt:="Insert Date", Type:=1) Cancel = True End Sub
试试这个:
Private Sub Workbook_Open() Dim inpt inpt = Application.InputBox(Prompt:="Insert Date", Type:=1) If CStr(inpt) <> "False" Then Sheets("Start").Range("B1").Value = inpt End Sub
我之所以使用CStr(inpt) <> "False"
而不是inpt <> False
或者只是If inpt Then
因为用户可以input0
(它是Input Type:=1
input框的有效inputType:=1
)
像这样(我已经包括今天的date作为默认select)
Dim lngCnt As Long lngCnt = Application.InputBox(Prompt:="Insert Date", Default:=Format(Now(), "dd-mmm-yy"), Type:=1) If lngCnt = 0 Then 'user cancelled Else Sheets("Start").Range("B1").Value = lngCnt End If