vb读取WPS的EXCEL文档并另存为其他

vb读取WPS的EXCEL文档并另存为其他,第1张

概述Dim xlAppDim xlApp2Dim xlBookDim xlBook2Dim xlSheetDim xlSheet2Dim getPathDim savePathDim re As RegExpDim msg As StringPrivate Sub Command1_Click()CommonDialog1.FileName = ""
Dim xlAppDim xlApp2Dim xlBookDim xlBook2Dim xlSheetDim xlSheet2Dim getPathDim savePathDim re As RegExpDim msg As StringPrivate Sub Command1_Click()CommonDialog1.filename = ""CommonDialog1.Flags = cdlOFNfileMustExistCommonDialog1.Filter = "All files|*.*|(*.xls)|*.xls"CommonDialog1.FilterIndex = 2CommonDialog1.DialogTitle = "打开文件(*.xls)"CommonDialog1.Action = 1getPath = CommonDialog1.filenameEnd SubPrivate Sub Command2_Click()If getPath <> "" ThenCommonDialog2.filename = ""CommonDialog2.Filter = "All files|*.*|(*.xls)|*.xls"CommonDialog2.FilterIndex = 2CommonDialog2.DialogTitle = "另存为(*.xls)"CommonDialog2.Action = 2savePath = CommonDialog2.filename    If savePath <> "" Then        '打开文件        Set xlApp = CreateObject("Excel.Application")        Set xlApp2 = CreateObject("Excel.Application")        Set xlBook = xlApp.Workbooks.Open(getPath)        Set xlSheet = xlBook.Worksheets(1)        '新建表格        Set xlBook2 = xlApp2.Workbooks.Open(App.Path & "\" & "模板文件.xls")        Set xlSheet2 = xlBook2.Worksheets(1)        '读取并修改文件        xlSheet2.Range("a2") = xlSheet.Range("a2")        xlSheet2.Range("d2") = xlSheet.Range("e2")        xlSheet2.Range("n2") = xlSheet.Range("d2")        xlSheet2.Range("o2") = xlSheet.Range("f2")        xlSheet2.Range("p2") = xlSheet.Range("g2")        xlSheet2.Range("q2") = xlSheet.Range("h2")        xlSheet2.Range("s2") = xlSheet.Range("j2")        xlSheet2.Range("u2") = xlSheet.Range("i2")        xlSheet2.Range("ah2") = "$" & xlSheet.Range("b2")        msg = xlSheet.Range("c2")                '正则表达式解析msg信息        Set re = New RegExp        re.Pattern = "【(\d+)】(.*)\s\(商家编码:(\w+)\)\s\(产品数量:(\d+) pIEce\)"                If (re.Test(msg) = True) Then            Set re1 = re.Execute(msg)(0)            xlSheet2.Range("ae2") = re1.SubMatches(1)            xlSheet2.Range("ag2") = re1.SubMatches(2)            xlSheet2.Range("aj2") = re1.SubMatches(3)        End If                '保存并关闭文件        xlBook2.SaveAs filename:=savePath        xlBook.Close        xlApp2.Workbooks(1).Close SaveChanges:=False  '不保存关闭模板文件        xlApp.Quit        xlApp2.Quit        Set xlBook = nothing        Set xlBook2 = nothing        Set xlApp = nothing        Set xlApp2 = nothing        MsgBox "文件保存成功"    End IfEnd IfEnd Sub
总结

以上是内存溢出为你收集整理的vb读取WPS的EXCEL文档并另存为其他全部内容,希望文章能够帮你解决vb读取WPS的EXCEL文档并另存为其他所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/langs/1272335.html

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

发表评论

登录后才能评论

评论列表(0条)

保存