在有些客户的系统上出现了多开excel文件失败的问题问题如下
经过排查发现是第二次打开的excel窗口没有激活,从而导致窗口绑定失败。
因此配合窗口命令激活Excel窗口即可解决这个问题,下面是代码
Function myOpenExcel(excelPath, isShow= True, product="Excel", pwdOpen= "", pwdWrite= "")
Dim objExcelWorkBook
Dim excelName
excelName = File.BaseName(excelPath,True)
Try
objExcelWorkBook = Excel.OpenExcel(excelPath, isShow, product, pwdOpen, pwdWrite)
Catch error
Log.Warn("myOpenExcel: 打开失败\n" & cstr(error))
Try
#icon("@res:default.png")
Window.SetActive({"wnd":[{"cls":"XLMAIN","title": excelName & "*- Excel","app":"EXCEL"}]})
objExcelWorkBook = Excel.BindBook(excelName)
Catch error
log.error("myOpenExcel: 绑定 或 激活窗口失败\n" & cstr(error))
End Try
End Try
Return objExcelWorkBook
End Function