VBA RegExp 在 vbscript.regexp 工作时导致编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21139938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:24:08  来源:igfitidea点击:

VBA RegExp causes Compile error while vbscript.regexp works

regexvbaoutlook-vba

提问by Batandwa

I was writing a script for VBA, for Outlook 2013, that uses regular expressions and every example I find seems to use Set regex = New RegExpto create a RegExp object. When I tried this I got Compile error: User-defined type not defined.

我正在为 VBA 编写一个脚本,用于 Outlook 2013,它使用正则表达式,我发现的每个示例似乎都用于Set regex = New RegExp创建RegExp 对象。当我尝试这个时,我得到了Compile error: User-defined type not defined

I managed to get regular expressions to work using Set regex = CreateObject("vbscript.regexp").

我设法让正则表达式使用Set regex = CreateObject("vbscript.regexp").

Any reason why the first options is not working?

第一个选项不起作用的任何原因?

回答by Bernard Saucier

Probably only missing some dependencies, meaning some references should be added.

可能只缺少一些依赖项,这意味着应该添加一些引用。

Go to Tools -> References ->Find & check the "Microsoft VBScript Regular Expressions" (1.0 or 5.5 both work for me).

转到Tools -> References ->查找并检查“Microsoft VBScript 正则表达式”(1.0 或 5.5 都适用于我)。

回答by Axel

I know this question was already successfully answered, I just wanted to add a solution that worked for me.

我知道这个问题已经成功回答了,我只是想添加一个对我有用的解决方案。

Tools -> References - > "Microsoft VBScript Regular Expressions 5.5"was already activated.

Tools -> References - > "Microsoft VBScript Regular Expressions 5.5"已经激活。

Set regex = New RegExpcaused a compile error.

Set regex = New RegExp导致编译错误。

Set regex = New VBScript_RegExp_55.RegExpworks.

Set regex = New VBScript_RegExp_55.RegExp作品。