2015-11-11 109 views
0

我在VBA中有一个Do-While循环,要求用户输入他们的公司UserID。这用于在其个人文件夹中查找文件夹,这并不重要。输入框:类型不匹配错误

我使用的输入框,我不知道我会怎么回事做到这一点:

Do 
    filepath2 = Application.InputBox("Enter your User FDIC", "UFDIC") 
    If filepath2 = False Then Exit Sub 
    filepath3 = "C:\Users\" & filepath2 & "\Desktop\NSC\" 
    Dir (filepath3) 
Loop While Not Dir(filepath3) > "" 

所以基本上,这将询问用户名用户,如果用户选择按钮“取消“,它将退出分组。如果不是,它将采用UserID并确保它存在。 当涉及到线路

If filepath2 = False Then Exit Sub 

,由于它期待一个布尔值,我得到一个类型不匹配的错误,我想。

我应该使用输入框以外的东西吗?

如果不是,我该如何打字检查?

+0

无法使用Environ(“username”)返回正确的用户名? (也许作为默认值) – Tom

回答

0

我想通了。

简单得改变

If filepath2 = False Then Exit Sub 

If filepath2 = "False" Then Exit Sub 

只更改为String。

+1

不是通常的解决方案。 http://stackoverflow.com/questions/16061562/trouble-with-inputboxes&http://stackoverflow.com/questions/26264814/how-to-detect-if-user-select-cancel-inputbox-vba-excel – niton