2016-12-05 127 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 ..我认为这就是你一直试图说的一直。再次感谢你。