我试图在宏观背景下打开一本woorkbook。当用户退出打开文件对话框时,我当然希望程序退出。
但是这样做的每次尝试都失败了......
' Get the file to open
tempFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
到目前为止我尝试了什么:
' Catch abort of the open file dialog
If IsEmpty(tempFile) Then
End
End If
' Catch abort of the open file dialog
If IsEmpty(tempFile) Or Not tempFile Then
End
End If
' Catch abort of the open file dialog
If IsEmpty(tempFile) Or Not CBool(tempFile) Then
End
End If
' Catch abort of the open file dialog
If IsEmpty(tempFile) Or tempFile Like "false" Then
End
End If
无论如何,我总是得到#34;类型不匹配"错误。
答案 0 :(得分:4)
dim tempFile
tempFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
if tempFile = False then
'user cancelled the dialog. exit the code
else
msgbox "User wants to open the file at : " & tempFile
end if
答案 1 :(得分:-2)
另外,请小心,因为如果你这样做
dim tempFile as String
...这可能是正确的事情,那么你必须做这样的检查:
If tempFile = "False" Then
与谷物不符,但有效。