qq_36944937 2018-03-31 17:16 采纳率: 0%
浏览 1035
已结题

vbs显示Set str = file.readall 会报错 缺少对象800a01a8

我的1.txt文件里是aaa bbb ccc 2.txt文件里是www aaa bbb 是不是我文本文件里面随便写的数据不对啊???求解决
Dim sdict
Dim i
Dim keys
Call GetInfo(sdict)

Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象

Set ExcelBook = ExcelApp.Workbooks.Add

Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页
ExcelSheet.Activate

ExcelApp.DisplayAlerts = False

ExcelSheet.Name="sheet1"

      ExcelSheet.range("A1").Value = "blockname"
      ExcelSheet.range("B1").value="1.txt"
      ExcelSheet.range("C1").value="2.txt"


      '取出所有关键字
keys = sdict.Keys
'取出所有值
items =sdict.Items
'循环dir逐条输出到excel中
      For i = 0 To sdict.Count - 1
    ExcelSheet.cells(i+2,1).value=keys(i)
    '输出所有的值
    value=value&items(i)&vbCrlf

    if items(i) = 0 then
    ExcelSheet.cells(i+2,2).value="Y"
    ExcelSheet.cells(i+2,3).value="Y"
    elseif items(i) =1 then 
    ExcelSheet.cells(i+2,2).value="Y"
    ExcelSheet.cells(i+2,3).value="N"
    elseif items(i)=2   then
    ExcelSheet.cells(i+2,2).value="N"
    ExcelSheet.cells(i+2,3).value="Y"
    end if
Next

ExcelBook.SaveAs "f:\1.xlsx"
ExcelBook.close
set excelApp=nothing
set ExcelBook=nothing
set ExcelSheet=nothing

Public Function GetInfo(sdict)

Dim strarry1
Dim strarry2
Dim Count1
Dim Count2
Dim i
'读取txt1
Call ReadFile("f:\1.txt",strarry1)
'读取txt2
Call ReadFile("f:\2.txt",strarry2)

'数组长度
Count1 = ubound(strarry1) + 1
Count2 = ubound(strarry2) + 1
set sdict=CreateObject("Scripting.Dictionary")

'如果仅在txt1中存在时,标记为1
For i = 0 To Count1 - 1
    sdict.add strarry1(i),1
Next

For i = 0 To Count2 - 1
    '如果同时在txt1和txt2中存在时,标记为0
    if sdict.Exists(strarry2(i)) then
        sdict.add strarry2(i),0
    '如果仅在txt2中存在时,标记为2
    else
        sdict.add strarry2(i),2
    end if
Next


End Function

Public Function ReadFile(filePath,strarry)
    '读取txt文件
    Const ForReading = 1
    Dim fs
    Dim file
    Dim str


    Set fs = CreateObject("Scripting.FileSystemObject")
    Set file = fs.OpenTextFile(filePath, ForReading)
    Set str = file.readall

fs.close

If   str=" "   then   
        msgbox "txt为空" 
    Exit Function
End   if  

strarry = split(str,vbCrlf)  
Set fs = nothing
End Function
  • 写回答

1条回答 默认 最新

  • threenewbee 2018-03-31 19:53
    关注

    Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
    这个要求你的电脑中安装了office或者excel,而且是完整版

    你有安装么?

    如果你安装了,那么看下你的权限。

    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能