vbscript 将应用于一个 PST 文件的所有规则复制到另一个

vbscript copy all rules applied to one PST file to another

我有两个 pst 文件。我想将应用于第一个 pst 文件的所有规则应用到第二个 pst 文件。是否可以使用 vbscript 而不用 VBA 来做到这一点。我认为 VBA 只能在 Outlook 本身而不是独立脚本上 运行。

I have two pst files. I want to apply all rules that are applied to first pst file to second pst file. Is it possible to do this with vbscript and without VBA.

是的,可以使用 VBScript 执行此操作,因为 VBScript 可以使用与 VBA 相同的基于 COM 的 Outlook Office Automation API,除了对象是后期绑定的(所以如果有任何在您的脚本中输入错误,直到您 运行 它才知道它们。

要将 VBA 转换为 VBScript,您需要执行以下操作:

  1. 将您的 VBA 代码复制并粘贴到 *.vbs 文件中。
  2. 从变量声明中删除类型信息
  3. 可选,但强烈建议:在第 1 行添加 Option Explicit
  4. 更改 Office COM 自动化互操作代码以使用后期绑定 CreateObjectGetObject 函数而不是 VBA/VB6-specific 构造函数或 COM API来电。

    ' Change this VBA/VB6:
    Set reminder = New Outlook.Reminder
    ' To this VBS:
    Set reminder = CreateObject("Outlook.Reminder")
    
    ' Change this VBA/VB6:
    Set app = Outlook.Application
    ' To this VBS:
    Set app = GetObject("Outlook.Application")
    

所以这个 VBA:

Sub Foo()

    Dim foo As String
    foo = ""

    Dim reminder As Outlook.Reminder
    Set reminder = Outlook.Application.Reminders.Item(1)

End Sub

...变成这个 VBScript:

Option Explicit

Sub Foo()

    Dim foo
    foo = ""

    Dim reminder
    Set reminder = GetObject( "Outlook.Application" ).Reminders.Item(1)

End Sub

Call Foo ' Enter into the Foo() subroutine from the top-level script.

I think VBA can be run only on Outlook itself not as independent script.

这是事实,但是当使用 VBScript 时(当 运行 来自 cscriptwscript 或任何其他活动脚本宿主,如 IIS)时,您仍在使用同一个 Office automation API as VBA,所以你仍然需要在你的计算机上安装 Outlook 和 运行 正常桌面会话中的脚本(而不是会话 0 或作为无头进程)。您还需要确保脚本的主机具有与 Outlook 相同的 ISA ("bitness")(即 x86 与 x64)。