VBA 下载包含希伯来语的图片 URL
VBA Download Image URL that contains Hebrew
我有一个 link 文件名中包含希伯来语:http://erezshaked.com/wp-content/uploads/2014/06/תפוח.jpg
我正在尝试下载它,但它不允许我下载。我基本上是在尝试对其中的 slug 进行编码以使其成为:
http://erezshaked.com/wp-content/uploads/2014/06/%D7%AA%D7%A4%D7%95%D7%97.jpg
这样我就可以下载了。
我已经有一个代码可以从 URL 下载图像,但是当 URL 上有希伯来语时它不起作用。这是我的代码:
Sub Download_Image()
Dim objShell As Object
Dim objFolder As Object
Dim objFile As Object
Set objShell = CreateObject("Shell.Application")
URLDownloadToFile 0, Cells(2, 1).Value, "E:\temp\" & Cells(2, 2) & ".jpg", 0, 0
Set objFolder = objShell.Namespace("E:\temp\")
Set objFile = objFolder.ParseName(Cells(2, 2) & ".jpg")
End Sub
这是工作表的内容:
非常感谢您的帮助。
这适用于单元格 A1 设置为 http://erezshaked.com/wp-content/uploads/2014/06/תפוח.jpg:
Option Explicit
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Sub Download_Image()
Dim url As String
Dim enc As String
url = Range("A1").Value
enc = WorksheetFunction.EncodeURL(url)
enc = Replace(enc, "%3A", ":")
enc = Replace(enc, "%2F", "/")
URLDownloadToFile 0, enc, "E:\temp\test.jpg", 0, 0
End Sub
我有一个 link 文件名中包含希伯来语:http://erezshaked.com/wp-content/uploads/2014/06/תפוח.jpg
我正在尝试下载它,但它不允许我下载。我基本上是在尝试对其中的 slug 进行编码以使其成为: http://erezshaked.com/wp-content/uploads/2014/06/%D7%AA%D7%A4%D7%95%D7%97.jpg
这样我就可以下载了。
我已经有一个代码可以从 URL 下载图像,但是当 URL 上有希伯来语时它不起作用。这是我的代码:
Sub Download_Image()
Dim objShell As Object
Dim objFolder As Object
Dim objFile As Object
Set objShell = CreateObject("Shell.Application")
URLDownloadToFile 0, Cells(2, 1).Value, "E:\temp\" & Cells(2, 2) & ".jpg", 0, 0
Set objFolder = objShell.Namespace("E:\temp\")
Set objFile = objFolder.ParseName(Cells(2, 2) & ".jpg")
End Sub
这是工作表的内容:
这适用于单元格 A1 设置为 http://erezshaked.com/wp-content/uploads/2014/06/תפוח.jpg:
Option Explicit
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Sub Download_Image()
Dim url As String
Dim enc As String
url = Range("A1").Value
enc = WorksheetFunction.EncodeURL(url)
enc = Replace(enc, "%3A", ":")
enc = Replace(enc, "%2F", "/")
URLDownloadToFile 0, enc, "E:\temp\test.jpg", 0, 0
End Sub