vb在同一文件夹下将excel文件转换为csv文件

时间:2024-11-01 08:57:43

1、在窗体上添加一个CommonDialog控件,一个命令按钮

2、编写打开代码Public xap As Excel.ApplicationPublic xbook1 As Excel.WorkbookFunction shezhi()Set xap = CreateObject("Excel.Application")End FunctionPrivate Sub dkdj_Click()Dim i As IntegerDim str As StringCall shezhiCommonDialog1.Action = 1Set xbook1 = xap.Workbooks.Open(CommonDialog1.FileName)

3、续写转换才csv文件代码Label1.Caption = CommonDialog1.FileName &#泌驾台佐39;取文件路径全名 i = Len(CommonDialog1.FileName) '计算取文件路径全名长度 str = Left(CommonDialog1.FileName, i - 4) '取文件路径(不包含后缀) Label2.Caption = str & ".csv" '转换为csv文件 xbook1.SaveAs FileName:=Label2.Caption, FileFormat:=xlCSV, CreateBackup:=False xbook1.Close End Sub

© 手抄报圈