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