Calltech
New Member
- Joined
- Dec 4, 2015
- Messages
- 19
Hello!
I would like to ask for help to a macro issue.
I found a solution to: Download Image from B column to specific path with renamed by A column. Add text to C, if it's successful or not.
Before macro:
[TABLE="width: 650"]
<tbody>[TR]
[TD]PIC NAME[/TD]
[TD]URL[/TD]
[/TR]
[TR]
[TD]350x150[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=33&txt=350%C3%97150&w=350&h=150[/TD]
[/TR]
[TR]
[TD]300x200[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=28&txt=300%C3%97200&w=300&h=200[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
After macro:
[TABLE="width: 850"]
<tbody>[TR]
[TD]PIC NAME[/TD]
[TD]URL[/TD]
[TD]Status[/TD]
[/TR]
[TR]
[TD]350x150[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=33&txt=350%C3%97150&w=350&h=150[/TD]
[TD]File successfully downloaded[/TD]
[/TR]
[TR]
[TD]300x200[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=28&txt=300%C3%97200&w=300&h=200[/TD]
[TD]File successfully downloaded[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
Here is the macro:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Option Explicit
PrivateDeclareFunction URLDownloadToFile Lib"urlmon" _
Alias"URLDownloadToFileA"(ByVal pCaller AsLong, _
ByVal szURL AsString,ByVal szFileName AsString, _
ByVal dwReserved AsLong,ByVal lpfnCB AsLong)AsLong
Dim Ret AsLong
'~~> This is where the images will be saved. Change as applicable
Const FolderName AsString="C:\Temp"
Sub Sample()
Dim ws As Worksheet
Dim LastRow AsLong, i AsLong
Dim strPath AsString
'~~> Name of the sheet which has the list
Set ws = Sheets("Sheet1")
LastRow = ws.Range("A"& Rows.Count).End(xlUp).Row
For i =2To LastRow '<~~ 2 because row 1 has headers
strPath = FolderName & ws.Range("A"& i).Value &".jpg"
Ret = URLDownloadToFile(0, ws.Range("B"& i).Value, strPath,0,0)
If Ret =0Then
ws.Range("C"& i).Value ="File successfully downloaded"
Else
ws.Range("C"& i).Value ="Unable to download the file"
EndIf
Next i
EndSub
</code>
Many people has error with this macro:
Compile error: The code in this project must be updated for use on64-bit systems.
The solution if change the macro codes to it:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Option Explicit
PrivateDeclareFunction URLDownloadToFile Lib"urlmon" _
Alias"URLDownloadToFileA"(ByVal pCaller AsLong, _
ByVal szURL AsString,ByVal szFileName AsString, _
ByVal dwReserved AsLong,ByVal lpfnCB AsLong)AsLong
Dim Ret AsLong
'~~> This is where the images will be saved. Change as applicable
Const FolderName AsString="C:\Temp"
</code>But I still have a continue error:
I would like to ask for help why can't working this macro for me?
I tried to change the URLDownloadToFile code row to others still unsuccessfully.
Thank you all in advance for your help!
Calltech
I would like to ask for help to a macro issue.
I found a solution to: Download Image from B column to specific path with renamed by A column. Add text to C, if it's successful or not.
Before macro:
[TABLE="width: 650"]
<tbody>[TR]
[TD]PIC NAME[/TD]
[TD]URL[/TD]
[/TR]
[TR]
[TD]350x150[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=33&txt=350%C3%97150&w=350&h=150[/TD]
[/TR]
[TR]
[TD]300x200[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=28&txt=300%C3%97200&w=300&h=200[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
After macro:
[TABLE="width: 850"]
<tbody>[TR]
[TD]PIC NAME[/TD]
[TD]URL[/TD]
[TD]Status[/TD]
[/TR]
[TR]
[TD]350x150[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=33&txt=350%C3%97150&w=350&h=150[/TD]
[TD]File successfully downloaded[/TD]
[/TR]
[TR]
[TD]300x200[/TD]
[TD]https://placeholdit.imgix.net/~text?
txtsize=28&txt=300%C3%97200&w=300&h=200[/TD]
[TD]File successfully downloaded[/TD]
[/TR]
[TR]
[TD]...[/TD]
[TD]...[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]
Here is the macro:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Option Explicit
PrivateDeclareFunction URLDownloadToFile Lib"urlmon" _
Alias"URLDownloadToFileA"(ByVal pCaller AsLong, _
ByVal szURL AsString,ByVal szFileName AsString, _
ByVal dwReserved AsLong,ByVal lpfnCB AsLong)AsLong
Dim Ret AsLong
'~~> This is where the images will be saved. Change as applicable
Const FolderName AsString="C:\Temp"
Sub Sample()
Dim ws As Worksheet
Dim LastRow AsLong, i AsLong
Dim strPath AsString
'~~> Name of the sheet which has the list
Set ws = Sheets("Sheet1")
LastRow = ws.Range("A"& Rows.Count).End(xlUp).Row
For i =2To LastRow '<~~ 2 because row 1 has headers
strPath = FolderName & ws.Range("A"& i).Value &".jpg"
Ret = URLDownloadToFile(0, ws.Range("B"& i).Value, strPath,0,0)
If Ret =0Then
ws.Range("C"& i).Value ="File successfully downloaded"
Else
ws.Range("C"& i).Value ="Unable to download the file"
EndIf
Next i
EndSub
</code>
Many people has error with this macro:
Compile error: The code in this project must be updated for use on64-bit systems.
The solution if change the macro codes to it:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Option Explicit
PrivateDeclareFunction URLDownloadToFile Lib"urlmon" _
Alias"URLDownloadToFileA"(ByVal pCaller AsLong, _
ByVal szURL AsString,ByVal szFileName AsString, _
ByVal dwReserved AsLong,ByVal lpfnCB AsLong)AsLong
Dim Ret AsLong
'~~> This is where the images will be saved. Change as applicable
Const FolderName AsString="C:\Temp"
</code>But I still have a continue error:
I would like to ask for help why can't working this macro for me?
I tried to change the URLDownloadToFile code row to others still unsuccessfully.
Thank you all in advance for your help!
Calltech
Last edited: