此位置已存在名为“XX\Data\AccNum.xls”的文件。要替换它吗?

A file named "XX\Data\AccNum.xls' already exists in this location. Do you want to replace it?

有人可以解释一下 here.The 下面的代码绝对有效,但它一直困扰着我:

A file named "XX\Data\AccNum.xls" already exists in this location. Do you want to replace it?

对于所有行。

有好几次,我必须单击“是”才能执行其余代码。我试过 displayAlert=Falseapplicationalerts=false。没有运气。

For Iterator = 1 To AccNoRow Step 1

    Set AccNoTB=browser("title:=.*").page("title:=.*").webtable("column names:=;Account No;Account Name;Billing City;Website;Phone;Assigned To;Action","cols:=8")

    'open excel & write to it

    Set Fso=createobject("Excel.application")
    Set file =fso.workbooks.open("XX\Data\AccNum.xls")
    file.worksheets("sheet1").cells(Iterator,3).value=AccNoTB.GetCellData(Iterator,3)
    fso.ActiveWorkbook.saveAs "XX\Data\AccNum.xls"
    fso.quit
Next

Set fso=nothing
Set file=nothing

您 "think" 遇到的问题的解决方案是使用 ActiveWorkbook.save 而不是 ActiveWorkbook.saveas,但代码的真正问题是,您创建了一个新的 excel 对象的每一行,这是绝对没有必要的。只需创建一次对象并在添加所有行后将其保存一次:为您节省大量开销,加快代码速度,这只是正确的方法。

'open excel & write to it

Set Fso=createobject("Excel.application")
Set file =fso.workbooks.open("XX\Data\AccNum.xls")

For Iterator = 1 To AccNoRow Step 1
    Set AccNoTB=browser("title:=.*").page("title:=.*").webtable("column names:=;Account No;Account Name;Billing City;Website;Phone;Assigned To;Action","cols:=8")
    file.worksheets("sheet1").cells(Iterator,3).value=AccNoTB.GetCellData(Iterator,3)
Next

fso.ActiveWorkbook.save
fso.quit

Set fso=nothing
Set file=nothing