使用VBScript在Excel中删除空白行

我们从源码系统获得excel文件,我们需要将其转换为CSV。 有时,excel文件的最后一行,我们得到空行。 我们需要在将文件放置为CSV之前删除该行。 我使用下面的代码来做这个转换,但它不会一直工作。它仍然保留空行导致转换为CSV时出现问题,最后一行CSV只显示逗号。

以下是脚本

Dim StrSourcePathFile, StrDestPathFile set xlApp = CreateObject("excel.application") Set fso = CreateObject("Scripting.FileSystemObject") StrSourcePathFile = "c:\temp\var31.XLSX" StrDestPathFile = "c:\temp\var31.csv" xlApp.Workbooks.Open StrSourcePathFile xlApp.DisplayAlerts = False If xlApp.ActiveSheet.Rows(1).Text = "" Then xlApp.ActiveSheet.Rows(1).EntireRow.Delete End If If xlApp.ActiveSheet.Rows((xlApp.ActiveSheet.UsedRange.Rows.Count)).Text = "" Then xlApp.ActiveSheet.Rows((xlApp.ActiveSheet.UsedRange.Rows.Count)).EntireRow.Delete End If xlApp.ActiveWorkbook.SaveAs StrDestPathFile,6 xlApp.ActiveWorkbook.Saved = true xlapp.Quit() Set fso = Nothing Set xlApp = Nothing 

提前致谢。