Board logo

标题: [问题求助] VBS怎样批量将Excel表格有效数据区域的空白单元格填写为0? [打印本页]

作者: nihaoareyou    时间: 2015-1-27 09:28     标题: VBS怎样批量将Excel表格有效数据区域的空白单元格填写为0?

有很多个excel文件,每个excel里面没有值的部分都是空白,现在想全部替换为0.
比如:
系数            总有效值           有效系数
2.4981                            7.19
2.5267                            5.12
2.5776                            4.35
2.571                            4.48
改为:
系数            总有效值           有效系数
2.4981                0           7.19
2.5267                0           5.12
2.5776                0           4.35
2.571                0           4.48[list=1]
作者: pcl_test    时间: 2016-7-24 14:28

  1. Set fso = CreateObject("Scripting.FileSystemObject")
  2. Set xlsApp = CreateObject("Excel.Application")
  3. Set Folder = fso.GetFolder(".")
  4. For Each File In Folder.Files
  5.     If LCase(Right(File.Path, 3)) = "xls" Then
  6.         Repxls File.Path
  7.     End If
  8. Next
  9. xlsApp.Quit
  10. msgbox "Done"
  11. Function Repxls(file)
  12.     Set objBook = xlsapp.Workbooks.Open(file)
  13.     For i=1 To objBook.sheets.count
  14.         If objBook.sheets(i).UsedRange.count > 1 Then
  15.             For Each cell In objBook.sheets(i).UsedRange
  16.                   If cell.value = "" Then cell.value = 0
  17.             Next
  18.         End If
  19.     Next
  20.     objBook.Save
  21.     objBook.Close
  22.     Set objBook=Nothing
  23. End Function
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2