资源描述:
《vb导出到excel文件(export vb to excel file)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、vb导出到excel文件(ExportVBtoexcelfile)ExportVBtoEXCELfileCategory:VBRecommendation:****indexDocumentpopularity:3160Popularitythisweek:11Releasedate:2007-3-26Private,Sub,cmdSwatch_Click()DimxlsAsexcel.ApplicationDimxlbookAsexcel.Workbook'OnErrorGoToexlErrorDimIAsInte
2、gerIfDir(Text1.Text)asafilewiththesamenamegivenprompt"Then'"<>thisdirectory,andthecorrespondingtreatmentIfMsgBox("thefilealreadyexists,isitcovered?"!"VbYesNo+vbQuestion,saveasprojectcostfile"==vbNoThenExitSubElseKill(Text1.Text)'deletefile'EndIfEndIf'**********
3、**openworksheet***************SetXLS=Newexcel.ApplicationXls.Visible=TrueSetxlbook=xls.Workbooks.Add'*********************************ForI=0,To14IfCheck2(I).Value=vbCheckedThenSelectCaseICase8ToExcelJDanJiaSum.ToExcelJDanJiaSum,xlbook,xlsCase9ToExcelADanJiaSum.
4、ToExcelADanJiaSum,xlbook,xlsCase10ToExcelCailiao.ToExcelCailiao,xlbook,xlsCase11ToExcelTsf.ToExcelTsf,xlbook,xlsCase12ToExcelZgcl.ToExcelZgcl,xlbook,xlsEndSelectEndIfNextForI=0,To6IfCheck3(I).Value=vbCheckedThenSelectCaseICase0ToExcelMan.ToExcelMan,xlbook,xlsCa
5、se1ToExcelFSD_CL.ToExcelFSD_CL,xlbook,xlsCase2ToExcelHNT.ToExcelHNT,xlbook,xlsCase3ToExcelZsf.ToExcelZsf,xlbook,xlsCase4ToExcelJingChang.ToExcelJingChang,xlbook,xlsCase5ToExcelJDanJia.ToExcelJDanJia,xlbook,xlsCase6ToExcelADanJia.ToExcelADanJia,xlbook,xlsEndSele
6、ct最后如果下一个xlbook.saveastext1。文本的保存Excel文件“***************************关闭Excel对象*******************如果会员。值=vbchecked然后xlbook。关闭xls。退出最后如果集xlbook=没有集XLS=没有退出子“exlerror:“MsgBox犯错。描述信息+vbcritical,“警告”端子明确选择市民SubToExcelZgcl(ByRefxlbook,我的输出总工程量XLS)昏暗的CONADODB连接新。昏暗的rst
7、_gcl作为新的数据集。昏暗的rst_qm作为新的数据集。“**************************连接数据库****************************************con.cursorlocation=aduseclientcon.connectionstring=“商=微软。飞机。OLEDB数据源。4;=“strconnection&”;坚持安全信息=假”CON。开放rst_gcl.open”zonggcl”,反对,adlockoptimistic,adcmdtable”打开工
8、程量汇总表adOpenKeyset,如果不是(rst_gcl.bof和rst_gcl。EOF)然后rst_gcl.movefirst最后如果rst_qm.open“明”,反对,adlockoptimistic,adcmdtable”打开签名表adOpenKeyset,rst_qm.movefirst“**********************