Board logo

标题: [问题求助] VBS如何将excel中某个区域的数据另存到txt中? [打印本页]

作者: yuzz1    时间: 2022-8-6 15:48     标题: VBS如何将excel中某个区域的数据另存到txt中?

1、提取excel中某一列中的数据,此列中需要的数据会在solder这样字符中间。
2、提取excel中某一行中的数据,此行中需要的数据会再solder这样字符之前。
作者: flashercs    时间: 2022-8-6 21:30

本帖最后由 flashercs 于 2022-8-6 21:31 编辑
  1. Set excel=CreateObject("Excel.Application")
  2. Set book=excel.Workbooks.Open("d:\test\a.xlsx")
  3. Set sheet=book.Worksheets(1)
  4. Set orange=sheet.UsedRange
  5. Set fso=CreateObject("Scripting.Filesystemobject")
  6. Set ts=fso.OpenTextFile("a.txt",2,True)
  7. For Each cell In orange.Columns(1).Cells
  8.   value=cell.Value()
  9.   If Instr(1,value,"solder")>0 Then
  10.     ts.WriteLine value
  11.   End If
  12. Next
  13. For Each cell In orange.Rows(2).Cells
  14.   value=cell.Value()
  15.   If Instr(1,value,"solder")>0 Then
  16.     ts.WriteLine value
  17.   End If
  18. Next
  19. ts.Close
  20. excel.Workbooks.Close
  21. excel.Quit
复制代码

作者: zss427607    时间: 2022-9-9 21:16

向大佬学习,顶起来




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