使用Excel VBA创build文件夹并从weblink上传图像?

我正在寻找方法来使用Excel创build一个约12000条目的文件夹系统,MkDirfunction似乎很容易,但我坚持如何让剩下的工作。 任何的意见都将会有帮助

我在想什么:

IndexID | Image 1 | sampleimage.com/images.jpg 2 | sampleimage.com/image.jpg 3 | sampleimage.com/moreimages.jpg 3 | sampleimage.com/evenmoreimages.jpg 

会变成这个文件结构:

 %dir%\Images\1\images.jpg %dir%\Images\2\image.jpg %dir%\Images\3\moreimages.jpg %dir%\Images\3\evenmoreimages.jpg 

或这个:

 %dir%\Images\1\1.jpg %dir%\Images\2\1.jpg %dir%\Images\3\1.jpg %dir%\Images\3\2.jpg 

我想使用VBA下载这些文件,如果他们还没有被下载并保存到适当的文件夹

这可以帮助你:

http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/beb6fa0e-fbc8-49df-9f2e-30f85d941fad/

他们展示了如何使用API​​从网上下载文件。 为了设置目录结构并把它们放在一起(这段代码不会运行…你必须添加API声明):

 Option Explicit ' api declarations go here ' ... Const directory As String = "C:\Images" Sub BacardiAndColaDoItDoIt() Dim sh As Excel.Worksheet Dim i As Long Dim iLastRow As Long Dim theFolderPath As String, theFilePath As String Dim fileName As String Set sh = ThisWorkbook.Worksheets("Sheet1") iLastRow = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row ' create first directory On Error Resume Next MkDir directory On Error GoTo 0 For i = 2 To iLastRow theFolderPath = directory & "\" & sh.Cells(i, 1).Value fileName = Mid(sh.Cells(i, 2).Value, InStrRev(sh.Cells(i, 2).Value, "/") + 1, Len(sh.Cells(i, 2).Value)) theFilePath = theFolderPath & "\" & fileName ' create subdirectory On Error Resume Next MkDir theFolderPath On Error GoTo 0 'DownloadFile(sh.Cells(i,2).value, theFilePath) Next i End Sub