VBA 中遇到一些奇怪的错误

发布于 2024-12-29 10:50:53 字数 432 浏览 5 评论 0原文

我正在做 powerpoint 2007 自动化项目。我正在使用宏编程(VBA)。运行宏时出现以下错误。

Err.Number= -2147024809 (80070057)

但我关心的不是错误,因为我想捕获此错误并基于此错误我想执行一些操作。

这就是为什么我尝试像这样编写错误处理代码:

OnError Goto Err:
'some code

Err:
If Err.number = -2147024809 (80070057) then
'do something
end if
Resume next

所以基本上,如果我以这种方式编写错误号,那么它就不允许它。它给出了错误。

最重要的是,当错误发生时,它不会出现“Err:”。它只是弹出带有“结束”和“调试”选项的错误。

I am doing project in powerpoint 2007 automation. In that i am using macro programming (VBA). I am getting the following error while run the macro.

Err.Number= -2147024809 (80070057)

but my concern is not with error Because i want to catch this error and base on this error i want to perform some action.

Thats why i try to code like this for error handing code:

OnError Goto Err:
'some code

Err:
If Err.number = -2147024809 (80070057) then
'do something
end if
Resume next

So bascially if i write error number in this way then its not allow it. it gives error.

and major thing is when error occurs sometime it did not go to "Err : ". It just pop-up error with "End" and "Debug" options.

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

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

发布评论

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

评论(3

纸短情长 2025-01-05 10:50:53

虽然它似乎有效,但一方面,我对使用保留对象名称(Err)作为标签持谨慎态度。

On Error GoTo ErrorHandler

' Your code here

' Make sure you don't hit the errorhandler when there's
' no error:
NormalExit:
Exit Sub ' or Function, whichever this is

ErrorHandler:
If err.Number = 123456788 Then
    ' Take corrective action
    ' then continue
    Resume Next
End If
' Trap other specific or general errors here

' Then make sure you know where you're going to exit:
Resume NormalExit

如果您需要捕获可能仅在代码中的某些位置发生的非常具体的错误,您还可以执行本地错误处理程序:

On Error Resume Next

' Some code that might cause problems

' Did it throw the error you're trying to trap?
If Err.Number = 12398745 then 
  ' Corrective action
End If

' And now we return to our regularly scheduled error trapping
On Error GoTo ErrorHandler

While it seems to work, I'd be cautious about using a reserved object name (Err) as a label, for one thing.

On Error GoTo ErrorHandler

' Your code here

' Make sure you don't hit the errorhandler when there's
' no error:
NormalExit:
Exit Sub ' or Function, whichever this is

ErrorHandler:
If err.Number = 123456788 Then
    ' Take corrective action
    ' then continue
    Resume Next
End If
' Trap other specific or general errors here

' Then make sure you know where you're going to exit:
Resume NormalExit

If you need to trap very specific errors that might occur only at certain places in your code, you can also do a local errorhandler:

On Error Resume Next

' Some code that might cause problems

' Did it throw the error you're trying to trap?
If Err.Number = 12398745 then 
  ' Corrective action
End If

' And now we return to our regularly scheduled error trapping
On Error GoTo ErrorHandler
︶ ̄淡然 2025-01-05 10:50:53

错误号是数字:-2147024809,为了清楚起见,它只是显示为字符串"-2147024809 (80070057)" ( 80070057) 是十六进制的错误号。

你想要;

if err.number = -2147024809 then ....

或者如果你这样选择

if err.number = &h80070057 then ....

Error numbers are numeric: -2147024809, its just displayed to you as the string "-2147024809 (80070057)" for clarity (80070057) being the error number in hexadecimal.

You want;

if err.number = -2147024809 then ....

or if you so choose

if err.number = &h80070057 then ....
a√萤火虫的光℡ 2025-01-05 10:50:53

错误消息的 80070057 部分是负数 -2147024809 的无符号十六进制版本。删除代码的这一部分就可以了,如果您想跟踪数字的十六进制版本(对于通过 Google 等研究错误很有用),那么只需将其添加为注释即可。

The 80070057 part of the error message is the unsigned hexadecimal version of the negative number -2147024809. Remove that part of your code and you will be fine, if you want to keep track of the hex version of the number (can be useful for researching errors via Google etc) then just add it as a comment.

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