1

我正在寻找使用 excel 为大约 12000 个条目创建文件夹系统的方法,MkDir 函数似乎很简单,但我一直坚持如何让其余的工作。任何的意见都将会有帮助

我在想什么:

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 下载这些文件

4

1 回答 1

2

这可能会帮助您:

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

他们展示了如何使用 API 从 Web 下载文件。用于设置目录结构并将其放在一起(此代码尚未运行...您必须添加 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
于 2013-03-05T15:49:23.290 回答