IE 10 打开另存为
IE 10 open save and save as
我目前正在编写一些代码来下载 CSV 文件并保存到特定文件夹中。
我目前从网上下载文件的方式是:
On Error Resume Next
With Workbooks.Open("Direct Link to the CSV or XLS File")
.SaveAs 'Name of file destination
.Close SaveChanges:=False 'Added this in due to a pop up appearing when downloading a CSV
End With
On Error GoTo 0
我要下载的这个特定文件只能在 IE 中下载。
这是我目前打开网页的代码:
Sub data()
Dim IE As Object
Dim Report As Variant
Set IE = CreateObject("INTERNETEXPLORER.APPLICATION")
IE.Navigate "Name of CSV File URL"
IE.Visible = True
End Sub
然后我会看到一个 windows 浏览器弹出窗口。下面的图片 link。
有什么想法可以 "click" 另存为按钮并将其放入文件路径。我可以想象 Sendkeys 是一个解决方案。
这适用于 IE10、运行 excel 2010 和 windows 7。
因此,经过一些试验后,我设法找到了解决方法。相反,我通过 excel.
使用网络查询打开它
代码如下:
Workbooks.add
With ActiveSheet.QueryTables.add(Connection:= _
"URL;http\:thelinkiused.csv" _
, Destination:=Range("$A"))
.Name = "transaction"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False
ActiveWorkbook.SaveAs Filepath & "\thelinkIused.csv"
ActiveWorkbook.Close savechanges:=False
这显然是一个非常基本的代码,不需要所有用于分隔数据的错误语句。
我目前正在编写一些代码来下载 CSV 文件并保存到特定文件夹中。
我目前从网上下载文件的方式是:
On Error Resume Next
With Workbooks.Open("Direct Link to the CSV or XLS File")
.SaveAs 'Name of file destination
.Close SaveChanges:=False 'Added this in due to a pop up appearing when downloading a CSV
End With
On Error GoTo 0
我要下载的这个特定文件只能在 IE 中下载。
这是我目前打开网页的代码:
Sub data()
Dim IE As Object
Dim Report As Variant
Set IE = CreateObject("INTERNETEXPLORER.APPLICATION")
IE.Navigate "Name of CSV File URL"
IE.Visible = True
End Sub
然后我会看到一个 windows 浏览器弹出窗口。下面的图片 link。
有什么想法可以 "click" 另存为按钮并将其放入文件路径。我可以想象 Sendkeys 是一个解决方案。
这适用于 IE10、运行 excel 2010 和 windows 7。
因此,经过一些试验后,我设法找到了解决方法。相反,我通过 excel.
使用网络查询打开它代码如下:
Workbooks.add
With ActiveSheet.QueryTables.add(Connection:= _
"URL;http\:thelinkiused.csv" _
, Destination:=Range("$A"))
.Name = "transaction"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False
ActiveWorkbook.SaveAs Filepath & "\thelinkIused.csv"
ActiveWorkbook.Close savechanges:=False
这显然是一个非常基本的代码,不需要所有用于分隔数据的错误语句。