gpt4 book ai didi

excel - 后期绑定(bind) Microsoft Windows 公共(public)控件 (TreeView) 对象

转载 作者:行者123 更新时间:2023-12-04 20:52:49 24 4
gpt4 key购买 nike

我已经使用 TreeView 在我的 Excel 数据库中实现了 DragDrop 功能。控制,使用此代码:

Private Sub TreeView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim StrPath As String

StrPath = Data.Files(1)
'path saved in UserForm label named "FilePathLB"
FilePathLB = StrPath

End Sub

它在我将文件分发到的大多数机器上都运行良好,但是由于无法找到 Microsoft Windows 通用控件库,一些具有旧版 MS Office 的机器在第一行 ( Private Sub ...) 上引发错误。

我的问题:是否可以后期绑定(bind)这个库,从而防止错误发生?

或者至少,是否可以添加一个调试器来防止显示错误,例如 On Error Resume Next对于整个子?我知道在这种情况下 DragDrop 功能不起作用,但它总比错误好。

最佳答案

对于你的最后一个问题:

Sub ()...
On Error GoTo ErrorHandler
'Your code
Exit Sub
ErrorHandler:
Msgbox "Could not load DragDrop function. Program execution has been terminated.", vbExclamation, "Error"
End Sub

如果你愿意,你也可以直接删除 MsgBox。

编辑:

将无法工作,因为代码在第一行中断。
下面的代码支持我的评论。如果子宏发生错误,则 PassedSub 变量不会被设置为 True,从而表示错误。
Public PassedSub As Boolean
Sub test1()

On Error Resume Next

Call test2
If PassedSub = False Then GoTo ErrorHandler
On Error GoTo 0

Exit Sub
ErrorHandler:
MsgBox "Could not load DragDrop function. Program execution has been terminated.", vbExclamation, "Error"
End Sub

Sub test2()

Debug.Print 2 / 0
PassedSub = True
End Sub

关于excel - 后期绑定(bind) Microsoft Windows 公共(public)控件 (TreeView) 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54549168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com