pb呼叫ole異常捕獲

回到未來望過去發表於2020-10-19
global type gf_title2cn from function_object
end type

forward prototypes
global function integer gf_title2cn (string fn)
end prototypes

global function integer gf_title2cn (string fn);

int li_result
string ls_v
ls_v=space(1000)

if outtype<>excel! then return 1 

//開啟指定的XLS檔案啟用workbooks
if fileexists(fn) then
	
	
	
MyOLE.application.workbooks.Open(fn)
//對XLS檔案進行了改動以後,在關閉該檔案時是否需要向使用者提出警告。

//ls_sheetname= MyOLE.ActiveWorkBook.Sheets[ii].name
//MyOLE.Worksheets("sheet1").Activate
MyOLE.ActiveWorkBook.Sheets(1).Select
//MyOLE.ActiveWorkBook.Sheets("sheet1").Select



int l_r,l_c
l_r=1
l_c=1
string ls_oldv,ls_newv


DO UNTIL isnull(MyOLE.cells(l_r,l_c).value)
	MyOLE.cells(l_r,l_c).NumberFormatLocal="@"
	ls_oldv=string(MyOLE.cells(l_r,l_c).value)
	ls_newv=gf_rename(ls_oldv)
		if ls_oldv<>ls_newv then
				MyOLE.cells(l_r,l_c).value=ls_newv
		end if
   l_c++
			yield()
LOOP


//----------
//MyOle.application.ActiveWorkbook.SaveAs(ls_pathname,3)

//
//MyOle.Worksheets("指標-24").Activate()
//MyOle.ActiveSheet.SaveAs("指標-24"+ls_pathname,3)
//myole.application.ActiveSheet.close()
//
try
myole.application.ActiveWorkbook.save()
catch (OLERuntimeError ex)
	messagebox("匯出",fn)
   messagebox('OLE錯誤',ex.getmessage())
	myole.application.ActiveWorkbook.close()
	
  // ole_object.application.quit()       //退出word  
   //斷開OLE連線
   //Ole_Object.DisConnectObject()
   //Destroy Ole_Object
   return 1
end try

myole.application.ActiveWorkbook.close()


//已經變成txt檔案了
end if
return 1




end function

 

相關文章