回答編集履歴

1

コード追加

2022/05/14 02:15

投稿

hatena19
hatena19

スコア33775

test CHANGED
@@ -10,3 +10,41 @@
10
10
  rc はLong型なので、`"TK0804"` の部分は数値でないとだめです。
11
11
 
12
12
  他にも `nsgBox "☆完了☆"` もエラーになります。`nsgBox`などという関数はありません。
13
+
14
+
15
+ ---
16
+ とりあえず下記のコードでどうですか。
17
+
18
+ ```vba
19
+ Option Explicit
20
+ Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias _
21
+ "URLDownloadToFileA" (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal _
22
+ szFileName As String, ByVal dwReserved As LongPtr, ByVal lpfnCB As LongPtr) As LongPtr
23
+
24
+ '簡略化【案】
25
+ Sub downloadimages()
26
+ Dim lastrow As Long
27
+ Dim rc As Long
28
+ Dim downloadStatus As Variant
29
+ Dim url As String
30
+ Dim desttinationFile_local As String
31
+
32
+ Dim Sheet2 As Worksheet
33
+ Set Sheet2 = Worksheets("Sheet2")
34
+
35
+ MkDir "D:\test"
36
+ lastrow = Sheet2.Range(Range("L2"), Range("L2").End(xlDown)).Count
37
+
38
+ For rc = 1 To lastrow
39
+ url = Sheet2.Cells(rc, 1).Value
40
+ desttinationFile_local = "D:\test\" & Sheet2.Cells(rc, "A").Value & ".jpg"
41
+ downloadStatus = URLDownloadToFile(0, url, desttinationFile_local, 0, 0)
42
+ Next
43
+
44
+ MsgBox "完了"
45
+
46
+ Shell "C:\Windows\explorer.exe " & "D:\test", vbNormalFocus
47
+
48
+ End Sub
49
+ ```
50
+