我有这样的链接" https://example.com.uk/download/report/2017-10-01_successful.csv",我无法下载CSV文件。
我必须每天通过此链接更改日期才能下载CSV文件。因此,我尝试了以下代码,其中A,B和C是特定日期的给定输入。
我的要求是:
我想通过更改链接中的日期值来下载此报告。我的代码添加了链接,但无法下载数据。
我该怎么办?在Excel VBA中需要引用任何库吗?
这是我的代码:
Sub Macro2()
Range("D14:L14").Select
Sheets("RAW_DATA").Select
Range("B26").Select
a = 2017
b = 10
c = 3
ActiveSheet.Shapes.Range(Array("Rectangle 11")).Select
'Selection.ShapeRange.Item(1).Hyperlink.Delete
ActiveSheet.Hyperlinks.Add Anchor:=Selection.ShapeRange.Item(1), Address:= _
"https://example.com.uk/Download/Report/" & a & "-" & b & "-" & c & "_successful.csv"
Range("D20").Select
Selection.ShapeRange.Item(1).Hyperlink.Follow NewWindow:=False, AddHistory:=True
Workbooks.Open Filename:= _
"https://example.com.uk/Download/Report/" & a & "-" & b & "-" & c & "_successful.csv"
ActiveWindow.Visible = False
Windows("2017-10-01_successful.csv").Visible = True
'Windows("ARC_ASC_TEMPLATE_VBA_V3.xlsm").Activate
End Sub
如果这不起作用,会发生什么?
Sub Macro2()
Dim wb As Workbook, fName, a, b, c
a = 2017
b = 10
c = 3
fName = "https://example.com.uk/Download/Report/" & a & "-" & _
Format(b, "00") & "-" & Format(c, "00") & "_successful.csv"
Set wb = Workbooks.Open(Filename:=fName)
Debug.Print wb.Name
End Sub