如何禁用Excel示例合并?

x9ybnkn6  于 2023-05-19  发布在  其他
关注(0)|答案(2)|浏览(95)

最新版本的Excel有一个新功能,如果Excel检测到一个已运行的会话,它会忽略对新会话的请求。我想知道如何阻止这一切。
此Microsoft支持文章建议添加注册表设置

Computer\HKCU\Software\Microsoft\Office\16.0\Excel\Options\DisableMergeInstance = 1

但这对我没用其他人可以测试它是否对他们有效并报告吗?
在此期间,我发现在启动新的Excel示例时按住ALT键会抛出一个对话框,上面写着“是否要启动Excel的新示例?(是/否)”,显示在此Microsoft article中。这是一个很好的解决办法,但我希望注册表设置的工作。

o4tp2gmn

o4tp2gmn1#

这是另一条路如果对你有用的话
btw的btw的btw!

Option Explicit

Private Declare Function IIDFromString Lib "ole32" (ByVal lpszIID As Long, IID As Any) As Long

Private Declare Function CoCreateInstance Lib "ole32" (rclsid As Any, ByVal pUnkOuter As Long, _
    ByVal dwClsContext As Long, riid As Any, ByVal ppv As Long) As Long

Private Declare Sub RtlMoveMemory Lib "kernel32" (pDst As Any, pSrc As Any, ByVal dlen As Long)

Private Const CLSID_EXCELAPP    As String = "{00024500-0000-0000-C000-000000000046}" ' Excel COM object GUID.

Private Const IID_DISPATCH      As String = "{00020400-0000-0000-C000-000000000046}" 'IDispatch Interface GUID.

Private Const IID_NULL          As String = "{00000000-0000-0000-0000-000000000000}"

Private Type GUID
    data1                       As Long
    data2                       As Integer
    data3                       As Integer
    data4(7)                    As Byte
End Type


Private Const CLSCTX_LOCAL_SERVER   As Long = &H4

Private Const S_OK                  As Long = &H0
Private Const E_NOINTERFACE         As Long = &H80004002
Private Const REGDB_E_CLASSNOTREG   As Long = &H80040154
Private Const CLASS_E_NOAGGREGATION As Long = &H80040110
Private Const E_POINTER             As Long = &H80004003

Sub CreateNewExcelInstance()
    Dim ExcelClassID        As GUID
    Dim IID                 As GUID
    Dim ObjectPtr           As Long
    Dim ExcelIIDHandle      As Long

    ExcelIIDHandle = IIDFromString(StrPtr(CLSID_EXCELAPP), ExcelClassID)
    If ExcelIIDHandle <> 0 Then Exit Sub

    ExcelIIDHandle = IIDFromString(StrPtr(IID_DISPATCH), IID)
    If ExcelIIDHandle <> 0 Then Exit Sub

    ExcelIIDHandle = CoCreateInstance(ExcelClassID, 0, CLSCTX_LOCAL_SERVER, IID, VarPtr(ObjectPtr))

    Debug.Print ExcelIIDHandle = S_OK

'''''''''''''''''''''''''
'
'    -> If you want the second instance to be visible:
'
'               Dim SecondExcelInstance as Object
'
'               RtlMoveMemory SecondExcelInstance, ObjectPtr, 4
'
'               SecondExcelInstance.Visible = True
'               SecondExcelInstance.Workbooks.Add
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
iklwldmw

iklwldmw2#

我知道这篇文章有点旧,但这是为那些通过网络搜索找到这篇文章的人准备的。
注册表项不应该在计算机配置单元中,而应该在HKEY_CURRENT_USER配置单元中。
https://learn.microsoft.com/en-US/office/troubleshoot/excel/force-excel-to-open-new-instance

相关问题