You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Excel中打开控制台窗口?调用AllocConsole报错87求解决

在Excel中调用AllocConsole函数报错87(参数不正确)的问题

我需要在Excel中打开控制台窗口以显示调试信息,目前已通过UserForm、即时窗口和文件记录调试信息,但尝试使用AllocConsole函数时失败,报错87:参数不正确。

使用环境:Windows 10(20H2)系统下的Excel 365(版本2207 内部版本1547.20284)

所用VB代码

Option Explicit

Private Declare PtrSafe Function FreeConsole Lib "kernel32" () As Long
Private Declare PtrSafe Function AllocConsole Lib "kernel32" () As Long

Sub Example()
    Dim l As Long
    
    l = FreeConsole
    Debug.Print "FreeConsole: " & l     ' 1
    
    If FreeConsole = 0 Then
        Debug.Print Err.LastDllError, "FreeConsole failed"
        Exit Sub
    End If
    
    l = AllocConsole
    Debug.Print "AllocConsole: " & l     ' 0
    
    If l = 0 Then
        Debug.Print Err.LastDllError ' 87 : The parameter is incorrect.
        Exit Sub
    End If
    
End Sub

输出结果

FreeConsole: 1
AllocConsole: 0
 87 

内容的提问来源于stack exchange,提问作者William Bettridge-Radford

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 13:35:33