PB打開EXCEL文件報錯

 

OLEObject ExcelServer
Integer ExcelOk
string ls_pathname

ls_pathname = "e:\gzdr\book1.xlsx"
IF FileExists(ls_pathname)=FALSE then
MessageBox("msg","File is not found")
return
end if

ExcelServer = CREATE OLEObject
ExcelOK = ExcelServer.ConnectToNewObject("excel.application")   
ExcelServer.Workbooks.Open(ls_pathname)   
//ExcelServer.ActiveWorkBook.Sheets("Sheet1").Select   
//ExcelServer.Application.Visible   =   TRUE     

//ExcelServer.ActiveWorkBook.Close()
ExcelServer.Quit


每次都是第8行報錯
ExcelServer.Workbooks.Open(ls_pathname)   
,但實際上是打開文件的


 

後來發現,需要讓EXCEL應用顯示出來,就不會報錯了,也不知道爲啥原因,所以只有顯示後馬上最小化

ExcelServer.Visible = TRUE
ExcelServer.WindowState = -4140  //最小化

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章