请帮助我改下:程序结束后不想还有许多WORD还在运行
我下面的程序结束后,一看进程列表,还有若士个WORD在运行(桌面上没有,是隐藏的),请帮助改正.
*ON ERROR *
********************
*aaa=ADIR(bbb,"c:\docs\*.doc")
*FOR i=1 TO ALEN(bbb,1)
*?bbb(i,1)
*next
********************
SET SAFETY off
TEXT
Declare Integer WinExec in kernel32 string, integer
m.llExist = .T.
Do While m.llExist
Try
m.loWord = Getobject(,'Word.Application')
m.loWord = Null
m.llExist = .T.
* 你结束 Word 的代码
MyCommand="TASKKILL /F /IM WINWORD.exe"
= WinExec (MyCommand,0)
Catch
m.llExist = .F.
Endtry
Enddo
Clear Dlls
ENDTEXT
fn2="c:\format.doc"
COPY FILE Format.doc TO (fn2)
thisform.zhuangtai.Caption='初始化文件夹……'
loFSO = CREATEOBJECT("Scripting.FileSystemObject")
IF directory("c:\docs")
loFSO.DeleteFolder("c:\docs")
ENDIF
loFSO.CreateFolder("c:\docs")
IF thisform.list1.ListCount=0
MESSAGEBOX("请选择至少一个数据文件!",0,"提示")
RETURN
ENDIF
eole=CREATEOBJECT('Excel.application')
*eole.visible=.t.
FOR i=1 TO thisform.list1.ListCount
eole.Workbooks.Open(thisform.list1.ListItem(i))
NEXT
SELECT cj
ZAP
kmlb = "思想政治语文数学物理化学生物历史地理外语音乐美术信息技术通用技术体育与健康"
IF DATE()>{^2010.6.1}
MESSAGEBOX("找不到相应组件。",0,"提示")
ENDIF
FOR j=1 TO eole.WorkBooks.Count
*SET STEP ON quit
FOR m.xjh=thisform.text1.Value TO thisform.text2.Value
FOR i=1 to eole.Workbooks(j).Worksheets.count
m.km=eole.Workbooks(j).workSheets(i).name
namedRange=eole.Workbooks(j).worksheets(i).Range([a1], [a10000])
tmpRange = namedRange.Find(STR(m.xjh,16))
IF m.km$kmlb
IF .not. ISNULL(tmpRange)
x=4
do while eole.Workbooks(j).workSheets(i).Cells(2, x).value=""
xm =eole.Workbooks(j).workSheets(i).Cells(tmpRange.Row, 2).value
sd=eole.Workbooks(j).workSheets(i).Cells(1, x-1).value
*IF sd='高1上学期'
***MESSAGEBOX(m.sd)
lb=eole.Workbooks(j).workSheets(i).Cells(2, x).value
***MESSAGEBOX(m.lb)
nr=eole.Workbooks(j).workSheets(i).Cells(2, x+1).value
dj=eole.Workbooks(j).workSheets(i).Cells(tmpRange.Row, x).value
xf=eole.Workbooks(j).workSheets(i).Cells(tmpRange.Row, x+1).value
SELECT cj
APPEND BLANK
REPLACE xjh WITH m.xjh
REPLACE sd WITH m.sd
REPLACE xm WITH m.xm
REPLACE km WITH m.km
REPLACE lb WITH m.lb
REPLACE dj WITH m.dj
IF TYPE("m.xf")="C"
m.xf=val(m.xf)
ENDIF
REPLACE xf WITH m.xf &&nr WITH m.nr,
*ENDIF
thisform.zhuangtai.Caption='抽取数据 学号:'+STR(m.xjh,16)+' '+'姓名:'+m.xm+' '+'科目:'+m.km
x=x+3
enddo
ENDIF
ENDIF
NEXT
NEXT
NEXT
thisform.Refresh
********
DIMENSION term(6)
term(1)='高1上学期'
term(2)='高1下学期'
term(3)='高2上学期'
term(4)='高2下学期'
term(5)='高3上学期'
term(6)='所有学期'
thisform.zhuangtai.Caption='正在合并数据……'
REPLACE ALL xm WITH strt(xm," ","")
select distinct xjh,xm from cj INTO table namelist
FOR k=1 TO 6
select xjh 学籍号,km 科目,;
SUM(ICASE("必修"==lb .and. INLIST(DJ,'A','B','C','D'),1,0)) as 必修科数,;
SUM(ICASE("选修I"==lb .and. INLIST(DJ,'A','B','C','D'),1,0)) as 选修1科数,;
SUM(ICASE("选修II"==lb .and. INLIST(DJ,'A','B','C','D'),1,0)) as 选修2科数,;
SUM(ICASE("必修"==lb .and. dj="A",1,0)) as 必修A数,;
SUM(ICASE("必修"==lb .and. dj="B",1,0)) as 必修B数,;
SUM(ICASE("必修"==lb .and. dj="C",1,0)) as 必修C数,;
SUM(ICASE("必修"==lb .and. dj="D",1,0)) as 必修D数,;
SUM(ICASE("选修I"==lb .and. dj="A",1,0)) as 选修1A数,;
SUM(ICASE("选修I"==lb .and. dj="B",1,0)) as 选修1B数,;
SUM(ICASE("选修I"==lb .and. dj="C",1,0)) as 选修1C数,;
SUM(ICASE("选修I"==lb .and. dj="D",1,0)) as 选修1D数,;
SUM(ICASE("选修II"==lb .and. dj="A",1,0)) as 选修2A数,;
SUM(ICASE("选修II"==lb .and. dj="B",1,0)) as 选修2B数,;
SUM(ICASE("选修II"==lb .and. dj="C",1,0)) as 选修2C数,;
SUM(ICASE("选修II"==lb .and. dj="D",1,0)) as 选修2D数,;
SUM(ICASE("必修"==lb,xf,0)) as 必修总分,;
SUM(ICASE("选修I"==lb,xf,0)) as 选修1总分,;
SUM(ICASE("选修II"==lb,xf,0)) as 选修2总分 ;
from cj WHERE sd=IIF("高"$term(k) .and. "学期"$term(k),term(k),"") GROUP BY xjh,km INTO table halfdone
SELECT a.*,b.xm 姓名,a.必修科数+a.选修1科数+a.选修2科数 等级数C FROM halfdone a JOIN namelist b ON a.学籍号=b.xjh INTO TABLE 无汇总
SELECT 无汇总
SELECT ;
学籍号,SPACE(8) 姓名, '合计' 科目,;
SUM(必修科数) 必修科数,;
SUM(选修1科数) 选修1科数,;
SUM(选修2科数) 选修2科数,;
SUM(必修A数) 必修A数,;
SUM(必修B数) 必修B数,;
SUM(必修C数) 必修C数,;
SUM(必修D数) 必修D数,;
SUM(选修1A数) 选修1A数,;
SUM(选修1B数) 选修1B数,;
SUM(选修1C数) 选修1C数,;
SUM(选修1D数) 选修1D数,;
SUM(选修2A数) 选修2A数,;
SUM(选修2B数) 选修2B数,;
SUM(选修2C数) 选修2C数,;
SUM(选修2D数) 选修2D数,;
SUM(必修总分) 必修总分,;
SUM(选修1总分) 选修1总分,;
SUM(选修2总分) 选修2总分,;
SUM(等级数C) 等级数C ;
from 无汇总 group by 学籍号 ;
INTO TABLE 汇总
SELECT 无汇总
APPEND FROM 汇总
********
*thisform.zhuangtai.Caption='正在生成表格……'
wole=Createobject('Word.application')
*wole.Visible=.T.
FOR m.xjh=thisform.text1.Value TO thisform.text2.Value
xjh0=m.xjh
wole.documents.Open('c:\format.doc')
xingming=""
SELECT 班级学号表
LOCATE FOR VAL(学籍号)=xjh0
IF FOUND()
banji=PADL(ALLTRIM(STR(班级)),2,'0')+'班'
ELSE
banji="无班"
ENDIF
SELECT 无汇总
Scan For 学籍号=xjh0
FOR i=1 TO 22
zd=Field(i)
IF INLIST(zd,'学籍号','科目','姓名')
loop
endif
If Empty(xingming)
xingming=姓名
xuejihao=STR(学籍号,16)
Endif
zd0=&zd
bookmark=Alltrim(科目)+zd
wole.ActiveDocument.Bookmarks(bookmark).Select
IF zd0>0
wole.Selection.TypeText(Alltrim(Str(zd0)))
endif
next
Endscan
thisform.zhuangtai.Caption='正在生成表格('+STR(xjh0,16)+' '+allt(xingming)+')……'
wole.ActiveDocument.Bookmarks("姓名").Select
wole.Selection.TypeText(ALLTRIM(xingming))
wole.ActiveDocument.Bookmarks("学籍号").Select
wole.Selection.TypeText(xuejihao)
wole.ActiveDocument.Bookmarks("年月日").Select
nian=STR(YEAR(thisform.rq.Value),4)
yue=STR(month(thisform.rq.Value),2)
ri=STR(day(thisform.rq.Value),2)
wole.Selection.TypeText(nian+"年"+yue+"月"+ri+"日")
* MESSAGEBOX(Directory("c:\docs"))
*MD c:\dosss
* banji=xxx
ThePath="c:\docs\"+banji+"_"+term(k)
IF .not. DIRECTORY(ThePath)
MD (ThePath)
ENDIF
filename=ThePath+'\'+Str(xjh0,16)+" "+xingming
*wole.ActiveDocument.WritePassword = "howareyou"
wole.ActiveDocument.SaveAs(filename)
IF thisform.dayin.Value=1
wole.ActiveDocument.PrintOut
ENDIF
wole.ActiveDocument.Close
Next
NEXT
wole.Quit
Release wole
eole.Quit
Release eole
thisform.zhuangtai.Caption='任务完成!'
RETURN
[解决办法]
把
wole.Quit
Release wole
移到
Next
之前
即原来:
Next
wole.Quit
Release wole
改为
wole.Quit
Release wole
Next