后期绑定的Microsoft Windows通用控件(TreeView控件)对象

问题描述 投票:2回答:1

我一直在使用TreeView控制实施的DragDrop功能,我的Excel数据库时,使用此代码:

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

它完美罚款我最分布式文件到机器的,但是有些机器与旧版本的MS Office上的第一行(Private Sub ...)由于未能找到Microsoft Windows公共控制库火灾错误。

我的问题:是否有可能后期绑定此库,从而防止错误的发生?

或者至少,是否有可能增加一个调试器来防止错误显示,像On Error Resume Next整个子?据我所知,在这种情况下的DragDrop功能是行不通的,但它是不是一个错误要好。

excel vba
1个回答
0
投票

为了您的最后一个问题:

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
© www.soinside.com 2019 - 2024. All rights reserved.