Sub test()
thesentence = InputBox("Type the filename with full extension", "Raw Data File")
Range("A1").Value = thesentence
If Dir("thesentence") <> "" Then
MsgBox "File exists."
Else
MsgBox "File doesn't exist."
End If
End Sub
在这种情况下,当我从输入框中提取文本值时,它不起作用。但是,如果从If
"the sentence"
中删除Dir()
并将其替换为代码中的实际名称,则可以使用。有人可以帮忙吗? 最佳答案
请注意,您的代码包含Dir("thesentence")
,应为Dir(thesentence)
。
将您的代码更改为此
Sub test()
thesentence = InputBox("Type the filename with full extension", "Raw Data File")
Range("A1").Value = thesentence
If Dir(thesentence) <> "" Then
MsgBox "File exists."
Else
MsgBox "File doesn't exist."
End If
End Sub