【问题标题】:Outlook VBA: PathSeparator Property Missing in Application ObjectOutlook VBA:应用程序对象中缺少 PathSeparator 属性
【发布时间】:2016-02-23 08:54:12
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 是什么让您认为该属性应该存在? IE。你以前见过的地方。显示一些参考资料。
  • 对此感到抱歉。我正在尝试循环浏览特定 Outlook 文件夹中的电子邮件,以将附件保存到 Windows 文件夹。一些附件是 zip 文件中的 Excel 文件,而其他附件只是 Excel。所以我有示例代码来解压缩它使用这个属性。请参阅上面的原始问题代码:
  • 请不要在 cmets 中粘贴代码。
  • 好的,我看到你的代码了。是什么让您认为应该存在名为Application.PathSeparator 的东西?你从哪里得到这个概念?
  • @roryap here

标签: vba outlook path-separator


【解决方案1】:

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 中可用的属性,并且不再真正使用它。 Here 是不同操作系统的路径分隔符列表,如果您有兴趣。

这是上面的代码,在 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

希望这会有所帮助!

【讨论】:

  • 谢谢安德鲁。这是一个巨大的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-03
相关资源
最近更新 更多