Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 我想在输入的末尾添加一个\_Excel_Vba_Input - Fatal编程技术网

Excel 我想在输入的末尾添加一个\

Excel 我想在输入的末尾添加一个\,excel,vba,input,Excel,Vba,Input,我想在输入的末尾添加一个\如果用户忘记输入斜杠,我的代码将无法工作。我该怎么做 我试过了 Path = InputBox("Paste the path of the folder:" & vbCrLf & "Pls end your path with a '\'" & vbCrLf & "e.g D:\work\path\") Filename = Dir(Path & "*.xl

我想在输入的末尾添加一个\如果用户忘记输入斜杠,我的代码将无法工作。我该怎么做

我试过了

Path = InputBox("Paste the path of the folder:" & vbCrLf & "Pls end your path with a  '\'" & vbCrLf & "e.g D:\work\path\")
Filename = Dir(Path & "*.xlsx")

如果正确(路径,1)\\,那么路径=路径&“\”
为什么不使用文件夹选择器而不是
输入框
Filename = Dir(Path & "\" & "*.xlsx")
Sub slashAtEnd()
    Dim Filename, Path
    For Each Path In Array("C:\temp", "C:\temp\")
        Filename = Dir(Path & Mid("\", 1 - (Path Like "*\")) & "*.xlsx")   ' works
        Filename = Dir(Path & "\*.xlsx")   'works too, even if with two \ at the end of "C:\temp\\"
        Debug.Print Filename
    Next
End Sub
'Output:
'Test.xlsx
'Test.xlsx