我有一个文件夹,里面有.tif和.tif 损坏的图像
Application.FollowHyperlink "G:Images" & ([Image_Name] & ".tiff")
该代码根据用户当前激活的图像名称打开图像。这是有效的,但没有考虑到文件可能是.tif或.tif
我该怎么做呢。
使用Dir()
函数查找目标目录中存在的文件名版本。然后打开那个文件。
Dim strNameFound As String
strNameFound = Dir("G:Images" & [Image_Name] & ".tif*")
Application.FollowHyperlink "G:Images" & strNameFound
一条评论指出,如果[Image_Name] & ".tif"
和[Image_Name] & ".tiff"
都存在,这种简单的方法将只打开找到的第一个名称,然后停止。如果两个文件名都存在,并且您希望同时打开这两个文件,则可以调整代码以再次调用Dir()
和FollowHyperlink
。
Dim strNameFound As String
strNameFound = Dir("G:Images" & [Image_Name] & ".tif*")
Do While Len(strNameFound) > 0
Application.FollowHyperlink "G:Images" & strNameFound
strNameFound = Dir
Loop