Vba - 错误不起作用? 读取注册表值

发布于 2024-07-23 06:02:25 字数 536 浏览 2 评论 0原文

这很奇怪,我有一个带有包含多个注册表项的数组的宏。 我想将这些值插入到 Word 文档中的预定义书签中。

如果密钥在那里,那么效果很好,但如果不存在,我希望代码跳过该密钥并继续尝试数组中的下一个。

我的代码如下所示:

sVerdi = objShell.RegRead(regPath & "\" & Felter(iTeller))

这行代码返回注册表项的值,由数组中的第一个项指定。 但是,如果注册表项不在注册表中,我自然会收到一个错误:

Run-time error '-2147024894(80070002)':

Unable to open registry key
"HKEY_CURRENT_USER\Blablabla" for reading

现在,这是合乎逻辑的,但如果我输入“On error GoTo 0”,那么它只会忽略该行。 我无法弄清楚,我一步一步地检查每个数组,但错误不断出现。

任何想法?

this is strange, I've got a macro with an array containing several registry keys.
And I want to insert the values of these into predefined bookmarks in a Word document.

This works great if the key is there, but if it isn't, I want the code to skip that and continue trying the next one in the array.

I've got the code that looks like this:

sVerdi = objShell.RegRead(regPath & "\" & Felter(iTeller))

This line of code returns the value of the registry key, dictated by the first in the array.
But, if the registry key isn't in the registry, I naturally get an error:

Run-time error '-2147024894(80070002)':

Unable to open registry key
"HKEY_CURRENT_USER\Blablabla" for reading

Now, this is logical, but if I throw in an "On error GoTo 0", then it just ignores that line. I can't figure it out, I go step by step through each array the error keeps coming.

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2024-07-30 06:02:25

当您说“它只是忽略该行”时,您的意思是 On Error GoTo 0 吗? On Error GoTo 0 并不意味着忽略错误:它意味着“恢复默认错误处理”。 您是否想使用 On Error Resume Next

When you say 'it just ignores that line, do you mean the On Error GoTo 0 ? On Error GoTo 0 doesn't mean ignore errors: it means 'restore default error handling'. Did you mean to use On Error Resume Next ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文