'在模块最前面添加下列代码
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Const OFS_MAXPATHNAME = 128
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Const OF_EXIST = &H4000 '判断文件是否存在的参数
'***********以下代码添加到子程序中
rc = OpenFile(Filename, Of1, OF_EXIST)
If rc < 0 Then
rc = MsgBox("文件不存在,操作无法继续", vbOK)
Exit Sub
End If