1

我正在尝试使用 Application.PathSeparator 属性。但是 PathSeparator 属性不可用于选择,如果我在我的 VBA 代码中输入它,我会收到运行时错误 438 - 对象不支持此属性或方法。

我需要安装什么东西才能访问 PathSeparator 吗?我有 MS Office 2007 和 Outlook 2010。我没有安装 .Net 客户端。

尝试在下面的示例代码中使用:

Sub UnZipFile(strTargetPath As String, Fname As String)
    Dim oApp As Object
    Dim FileNameFolder As Variant

    If Right(strTargetPath, 1) <> Application.PathSeparator Then
        strTargetPath = strTargetPath & Application.PathSeparator
    End If

    FileNameFolder = strTargetPath
    Set oApp = CreateObject("Shell.Application")
    oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(strTargetPath & Fname).items
    DoEvents
End Sub
4

1 回答 1

0

PathSeperator不是 的属性Outlook.Application。如果你真的想使用Application.PathSeperator,你可以添加一个引用,Microsoft Excel x.0 Object Library然后将此代码添加到项目的顶部:

Dim exapp As Excel.Application
Set exapp = New Excel.Application

...并将所有实例替换为Application.PathSeperator

exapp.PathSeparator

...但这可能是我写过的最愚蠢的代码。该PathSeperator属性所做的只是返回与设备相关的路径分隔符,因此在 Windows 中它返回字符串\。在 Outlook 获得 VBA 之前,它是 Excel VBA 中可用的属性,并且不再真正使用它。如果您有兴趣,这里是不同操作系统的路径分隔符列表。

这是上面的代码,在 Outlook 中工作:

If Right(strTargetPath, 1) <> "\" Then
    strTargetPath = strTargetPath & "\"
End If

FileNameFolder = strTargetPath
Set oApp = CreateObject("Shell.Application")
oApp.NameSpace(FileNameFolder).CopyHere oApp.NameSpace(strTargetPath & Fname).Items
DoEvents

希望这可以帮助!

于 2015-11-06T20:43:48.870 回答