第2个回答 2020-08-07
目前较通用的判断方式只用一行代码即可:
is_WPS = InStr(Replace(UCase(Application.Caption), UCase(Application.ActiveWorkbook.Name), ""), "WPS") > 0
在以下 3 个环境上实测通过, 未发现判断错误:
Excel 2016, WPS 表格 11.1.0.9912 (WPS 2019), WPS 表格 9.1.0.4472
以下是加了 3 行调试信息的检测函数:
Public Function is_WPS()
Debug.Print "Application.Build:" & vbCrLf & Application.Build
Debug.Print "Application.Caption:" & vbCrLf & Application.Caption
Debug.Print "Application.ActiveWorkbook.Name:" & vbCrLf & Application.ActiveWorkbook.Name
is_WPS = InStr(Replace(UCase(Application.Caption), UCase(Application.ActiveWorkbook.Name), ""), "WPS") > 0
End Function
在较低版 WPS 中,
Application.name
返回带有 "WPS" 字样
在WPS 2019 中,
Application.name,
ActiveWorkbook.Application.Value
都返回
Microsoft Excel
以下是在 各种环境下 立即窗口 的调试结果
运行环境: Excel 2016
运行显示:
?is_WPS
Application.Build:
13001
Application.Caption:
test.xlsm - Excel
Application.ActiveWorkbook.Name:
test.xlsm
False
运行环境: WPS 表格 11.1.0.9912 (WPS 2019)
运行显示:
?is_WPS
Application.Build:
9912
Application.Caption:
test.xlsm - WPS 表格
Application.ActiveWorkbook.Name:
test.xlsm
True
运行环境: WPS 表格 9.1.0.4472
运行显示:
?is_WPS
Application.Build:
9.1.0.4472
Application.Caption:
WPS 表格 - [test.xlsm *]
Application.ActiveWorkbook.Name:
test.xlsm
True
Application.Path 是不够可靠的, 如果你在安装 微软 Office 时在路径中用了 WPS 字样, 或者相反 的 在 安装 WPS 时在路径中 用了 microsoft 或者 excel 字样, 都会造成路径识别方式不可行