エクセル内にある画像URLをスクレイピングして、指定するフォルダに保存するVBAを作成したつもりでしたが、何度やってもfilenameにてエラーが発生します。
その他にもエラー箇所がありましたら、ご教授いただけますでしょうか。
また、以下コードにファイル名をL列に並んだB列のものに出来るようにしたいです。
※office365 64ビットとなります。
何卒よろしくお願いいたします。
Option Explicit
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As LongPtr, ByVal lpfnCB As LongPtr) As LongPtr
'簡略化【案】
Sub downloadimages()
Dim lastrow As Long
Dim rc As Long
On Error Resume Next
Dim downloadStatus As Variant
Dim url As String
Dim destinationFile_local As String
MkDir "C:\Users\Guest\Pictures"
lastrow = Sheet2.Range(Range("L2"), Range("L2").End(xlDown)).Count
For rc = "TK0804" To lastrow
url = Sheet2.Cells(rc, 1).Value
desttinationFile_local = "C:\Users\Guest\Pictures" & Filename(rc - 1 & ".jpg")
downloadStatus = URLDownloadToFile(0, url, desttinationFile_local, 0, 0)
Next
nsgBox "☆完了☆"
Call openFolder("C:\Users\Guest\Pictures")
End Sub
Sub openFolder(path As String)
Shell "C:\Windows\Explorer.exe " & path, vbNormalFocus
End Sub