想通过如下函数实现在工作簿所在文件夹中查找给定文件名的PDF文件是否存在。这个函数上周末我做好的时候还是可以正常地返回true或flase结果。但这两天再打开工作簿,所有的结果都变成了flase。不知道谁明白这是怎么回事。多谢。
Function checkfile(fn As String) As Boolean
'Use this function to check if the pdf file with variant name already exists in current folder
ffn = fn & ".pdf"
If Dir(ffn) <> "" Then
checkfile = True
Else
checkfile = False
End If
End Function
第1个回答 2013-08-14
1、在fn参数中应当指定路径
2、dir[(pathname[, attributes])]函数没有指定属性参数,则会返回匹配 pathname 但不包含属性的文件。
你的出错可能是没有指定路径或改变以文件 的属性。本回答被网友采纳
2、dir[(pathname[, attributes])]函数没有指定属性参数,则会返回匹配 pathname 但不包含属性的文件。
你的出错可能是没有指定路径或改变以文件 的属性。本回答被网友采纳
第2个回答 2013-08-13
DIR判断要路径的,所以要改一句:
Function checkfile(fn As String) As Boolean'Use this function to check if the pdf file with variant name already exists in current folder
ffn = ThisWorkbook.Path & "/" & fn & ".pdf"
If Dir(ffn) <> "" Then
checkfile = True
Else
checkfile = False
End If
End Function本回答被提问者采纳