1
我目前正在从一个网站抓取一个csv文件的项目,并将其放入我的工作簿中的预定义页面。它在某种程度上起作用,但它不断创建新的VBA项目,但我并没有真正理解,并最终停止运作。请注意,对于特定的网站,我从中提取这个我不能使用Internet Explorer。Excel导入文件时创建额外的VBA项目
的代码我使用:
Private Sub CommandButton3_Click()
On Error Resume Next
Kill "C:\Users\Me\Downloads\products.csv"
On Error GoTo 0
Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url url-string-here")
Application.Wait (Now + TimeValue("00:00:25"))
sCSVLink = "C:\Users\Me\Downloads\file.csv"
sfile = "file.csv"
ssheet = "CurrentListings"
Set wnd = ActiveWindow
Application.ScreenUpdating = False
Sheets(ssheet).Cells.ClearContents
Workbooks.Open Filename:=sCSVLink
Windows(sfile).Activate
ActiveSheet.Cells.Copy
wnd.Activate
Sheets("CurrentListings").Paste
Application.DisplayAlerts = False
Windows(sfile).Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Sheets("CurrentListings").Range("E:E").WrapText = False
End Sub
就像我说的,它会奏效了几次,但出现这种情况,每次:
最后,它给了我一个运行时错误, 有什么建议么?
什么是您看到的运行时错误? –
另外,看看[这](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros)。通常,依靠'ActiveSheet','ActiveWindow','Select'等导致代码非常难以解释。更好的范围适当的对象变量,并使用它们 - 更容易阅读,更容易调试,更容易在未来修复:) –
运行时错误'1004'它告诉我粘贴到第一个单元格的值,已经尝试过,但我仍然得到那个错误 –