我有前面提到的相同系统块,其中系统权限不允许我使用 Application.COMAddIns(Name).Connect = True。这是一种解决方法,但要让 COM 插件框弹出,您可以使用 SendKeys 将其拉起。请记住,SendKeys 仅在 Excel 2010 及更高版本上运行结束时执行,因此要使其正常工作,您需要首先检查用户是否连接到加载项。如果是这样,请调用另一个子;如果不使用 SendKeys 打开对话框并结束子。这些是对我有用的击键,可能需要进行一些编辑,具体取决于菜单中有多少选项。
Sub test()
'Checks if COM is installed and active
comFound = False
comRibbon = True
For i = 1 To Application.COMAddIns.Count
If Application.COMAddIns(i).Description = "NAME" Then
comFound = True
If Application.COMAddIns(i).Connect = False Then
comRibbon = False
End If
Exit For
End If
Next i
'Exits sub if not installed
If comFound = False Then
MsgBox ("You do not have NAME installed.")
Exit Sub
End If
'Directs user to rest of code if active, otherwise opens dialog
If comRibbon = True Then
Call test2
Else
MsgBox ("Please select NAME in the following dialog before rerunning.")
End If
SendKeys "%FT{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{TAB}{TAB}{TAB}{DOWN}{DOWN}{TAB}~", True
End Sub
Sub test2()
'Rest of code
End Sub