2013-02-01 21 views
1

在Excel中有使用application.inputbox將單元格中的日期保存的宏。輸入日期後,格式正確的日期出現在單元格中,然後輸入框再次打開。它似乎陷入了這個怪異的循環。無論我輸入多少次,它都會再次提問。Excel輸入框在輸入後重新打開

下面是這部分代碼:

Function freshSTART() 

redBOX.Cells(1).Value = Application.InputBox(prompt:="Enter todays date: ", Title:="TODAY'S DATE", Type:=1) 
redBOX.Cells(2).Value = Application.InputBox(prompt:="Enter customer's name: ", Title:="CUSTOMER NAME", Type:=2) 
redBOX.Cells(3).Value = Application.InputBox(prompt:="Enter travel out date: ", Title:="TRAVEL OUT DATE", Type:=1) 
redBOX.Cells(4).Value = Application.InputBox(prompt:="Enter travel back date: ", Title:="TRAVEL BACK DATE", Type:=1) 
redBOX.Cells(5).Value = Application.InputBox(prompt:="Enter number of technicians: ", Title:="TECHNICIANS", Type:=1) 
redBOX.Cells(6).Value = Application.InputBox(prompt:="Enter number of engineers: ", Title:="ENGINEERS", Type:=1) 
redBOX.Cells(7).Value = Application.InputBox(prompt:="Enter location: ", Title:="LOCATION", Type:=2) 

End Function 
+0

如何被觸發這個功能呢? (爲什麼不使用Sub,因爲這個代碼不會返回任何值?) –

回答

0

無論你是passing a parameter也不是你得到一個value returned。在這種情況下,擁有functionSubroutine沒有用。

您是否在Worksheet changedCell changed事件上致電此功能?當觸發上述事件的功能時,請使用Application.EnableEvents = False。你必須關閉事件,否則它會不斷重複拖動到無限循環。然後在change event轉回事件。

參考文獻:

+0

有趣。你說得對,功能沒有意義。改爲子,但問題仍然存在。宏從打開的工作簿調用。在通話完成之前使EnableEvents = False。我不太清楚這一點,所以我有很多東西需要學習。謝謝你的幫助! – user1542821