此宏使用 C 和 D 列中的多行 URL 从 Web 下载我需要的文件。但是,它将单元格 A1 的值添加为每个下载的文件名的前缀。
我需要帮助修改我的宏,以便不使用 Cell $A$1 作为每个下载文件的前缀,而是希望它使用同一行的“A”列中的值。
Dim URL As String
Dim LocalFileName As String
Dim B As Boolean
Dim ErrorText As String
Dim C As Range
Dim sTxt As String
sTxt = Cells(1, "a").Value
Dim Lastrow As Long
Lastrow = Range("C:D").Find("*", , , , xlByRows, xlPrevious).Row
For Each C In Range("C1:D" & Lastrow)
If Len(C) > 0 Then
URL = C.Text
' LocalFileName = "C:\downloaded\" & Range("A1") & " " & Evaluate("TRIM(RIGHT(SUBSTITUTE(""" & C.Text & """,""/"",REPT("" "",1000)),1000))")
B = DownloadFile(UrlFileName:=URL, _
DestinationFileName:=LocalFileName, _
Overwrite:=DoNotOverwrite, _
ErrorText:=ErrorText)
If B = True Then
Debug.Print "Download successful"
Else
Debug.Print "Download unsuccessful: " & ErrorText
End If
End If
Next C
End Sub
示例数据:
A B C D
1 12345 Record1 http://www.test.com/picture1.jpg http://www.test.com/file1.pdf
2 abcde Record2 http://www.test.com/Picture2.jpg http://www.test.com/file2.pdf
在上面的示例中,所需的文件名将是: -12345 picture1.jpg -12345 file1.pdf -abcde picture2.jpg -abcde file2.pdf
任何人?