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'它告訴我粘貼到第一個單元格的值,已經嘗試過,但我仍然得到那個錯誤 –