如何在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
相关产品推荐
相关产品推荐

