我正试图在后台的宏中打开一个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无论如何,我总是得到一个“类型不匹配”的错误。
发布于 2011-09-13 14:58:44
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发布于 2011-09-13 15:59:25
另外,要小心,因为如果你这样做了
dim tempFile as String...which可能是正确的选择,然后你必须像这样做检查:
If tempFile = "False" Then这与本意相反,但却是可行的。
https://stackoverflow.com/questions/7397776
复制相似问题