首页 > 解决方案 > Excel VBA:检查是否存在谷歌驱动器快捷方式

问题描述

我正在尝试检查是否存在通过用户的 Google Drive 的快捷方式

path = "G:\My Drive\Templates\"
If len(Dir(path, vbDirectory)) <> 0 Then
    'folder or shortcut exists

如果路径是文件夹,则此代码将起作用,但如果路径是快捷方式,则不会。

任何想法如何解决?提前致谢

标签: excelvba

解决方案


基于检索快捷方式属性

Sub test1()
    shk = "c:\temp\test.lnk"
    Set WshShortcut = CreateObject("WScript.Shell").CreateShortcut(shk)
    Path = WshShortcut.TargetPath
    If Dir(Path, vbDirectory) <> vbNullString Then
        Debug.Print "Path `" & Path & "` exists"
    End If
End Sub

推荐阅读