2016-12-05 59 views
0

我有一個代碼,要求輸入1-3之間使用InputBox然後運行一個代碼取決於它是什麼輸入。我的問題是,我不需要InputBox了,因爲我打算做的工作只使用一個輸入,它是3.我試圖刪除輸入框,並在那裏插入3,但然後代碼不做任何事情。然後我試圖在框中插入一個默認值,但它仍然出現,需要我點擊輸入,這是我想要避免的。請問我該如何解決這個問題。取消或隱藏輸入框在vba

我的代碼

Function GetTypeFile() As Integer 

    Dim strInput As String, strMsg As String 
    Dim Default 

    choice = 0 
    While (choice < 1 Or choice > 3) 
     Default = "3" 

     strMsg = "Type in the kind of entities to create (1 for points, 2 for points and splines, 3 for points, splines and loft):" 
     strInput = InputBox(Prompt:=strMsg, _ 
        Title:="User Info", Default:=3, XPos:=2000, YPos:=2000) 

     'Validation of the choice 
     choice = CInt(strInput) 
     If (choice < 1 Or choice > 3) Then 
      MsgBox "Invalid value: must be 1, 2 or 3" 
     End If 
    Wend 
    GetTypeFile = choice 

End Function 
+0

如果你總是把'3'放在什麼位置,你想要什麼來代替'InputBox'? 'GetTypeFile'將會是'3'。 –

+0

這就是問題所在,當我試圖消除'InputBox'的代碼,然後不做任何事情。當我試圖直接將值分配給'GetTypeFile'時,它仍然不起作用。 –

+0

所以你想要這個代碼做什麼?你想如何輸入1到3的輸入? –

回答

1

你的函數返回值,無論它的調用,所以你可以只使用:

Function GetTypeFile() As Integer 
    GetTypeFile = 3 
End Function 

或只是數量3更換任何調用函數。

因此,而不是像這樣:

Sub Test() 
    ThisWorkbook.SaveAs "MyFileName", GetTypeFile 
End Sub 

你必須:

Sub Test() 
    ThisWorkbook.SaveAs "MyFileName", 3 
End 
+0

感謝您的回覆。我嘗試了你所說的,但是當我嘗試運行它時,它什麼都不做。該過程應該導致它在CATIA中打開一個CAT文件。我也想嘗試直接從CATIA VBA運行代碼,而不必打開excel文件並單擊在excel文件中運行或在輸入框中輸入。 –

0

謝謝大家的回覆。我只是明白了該怎麼做,通過將取決於inputbox中的值的變量設置爲3而不是TypeDocument=GetTypeFile直接得到TypeDocument=3 ..我認爲這就是你一直試圖說的一直。再次感謝你。

相關問題