VB 通过指定Excel模板文件进行另存为新文件 *** 作

VB 通过指定Excel模板文件进行另存为新文件 *** 作,第1张

概述Private Sub cmdExport_Click()     Dim strTemplateFile         As String     Dim strFileName             As String     Dim FSO                     As New FileSystemObject     Dim excelApp               Private Sub cmdExport_Click() Dim strTemplatefile As String Dim strfilename As String Dim FSO As New fileSystemObject Dim excelApp As Excel.Application Dim excelBook As Excel.Workbook Dim excelSheet As Excel.Worksheet Dim lnglineNo As Long Dim i As Long On Error GoTo ErrHandle strTemplatefile = gStrXlt & "\模板文件名.xls" If Not FSO.fileExists(strTemplatefile) Then MsgBox "模板文件不存在",vbCritical,Me.Caption Exit Sub End If strfilename = gStrOther & "\新文件名" & Format(Date,"YYYYMMDD") & ".xls" If FSO.fileExists(strfilename) Then FSO.Deletefile strfilename End If Set excelApp = CreateObject("Excel.Application") Set excelBook = excelApp.Workbooks.Open(strTemplatefile) Set excelSheet = excelBook.Worksheets(1) excelApp.Visible = False excelApp.displayAlerts = False '禁止Excel提示 excelApp.Columns("A:L").NumberFormatLocal = "@" '设置成文本格式 With prg .Max = lvData.ListItems.Count .Min = 0 .Value = 0 End With lnglineNo = 4 '从第四行开始写 For i = 1 To lvData.ListItems.Count excelSheet.Cells(lnglineNo,1) = lvData.ListItems(i).SubItems(1) excelSheet.Cells(lnglineNo,2) = lvData.ListItems(i).SubItems(2) excelSheet.Cells(lnglineNo,3) = lvData.ListItems(i).SubItems(3) excelSheet.Cells(lnglineNo,4) = lvData.ListItems(i).SubItems(4) excelSheet.Cells(lnglineNo,5) = lvData.ListItems(i).SubItems(5) lnglineNo = lnglineNo + 1 If prg.Value < prg.Max Then prg.Value = prg.Value + 1 End If DoEvents Next prg.Value = prg.Max With excelSheet .Range(.Cells(1,1),Cells(lvData.ListItems.Count + 3,5)).borders.linestyle = xlContinuous .Range(.Cells(1,5)).Font.Size = 9 End With excelBook.Saved = True excelBook.SaveAs strfilename '关闭Excel进程 excelBook.Close excelApp.Quit Set excelBook = nothing Set excelApp = nothing MsgBox "导出完毕!" & vbCrLf & "文件路径:" & strfilename,vbinformation,Me.Caption On Error GoTo 0 Exit Sub ErrHandle: Call gErrList("frmFenQiQiShuRpt.cmdExport_Click",Err.Description,Err.Number,True) End Sub 总结

以上是内存溢出为你收集整理的VB 通过指定Excel模板文件进行另存为新文件 *** 作全部内容,希望文章能够帮你解决VB 通过指定Excel模板文件进行另存为新文件 *** 作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1280133.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存