【问题标题】:Download files from Microsoft Excel sheet using VBA使用 VBA 从 Microsoft Excel 工作表下载文件
【发布时间】:2017-05-09 18:44:35
【问题描述】:

我有一个包含文件夹名称和图像 URL 的工作表。 我想将所有图像下载到特定文件夹。

enter image description here 有人知道怎么做吗? 谢谢

【问题讨论】:

  • 嗨,Spechal,我没有任何编程知识和背景。不知道该怎么做。
  • 嗨 Rehban Khatri,我想把它下载到我的电脑上,而不是在 excel 中
  • "我没有任何编程知识和背景。"因此,如果不先获得 VBA 编程知识,您就无法自己做到这一点。但是这个站点不是一个教授编程的站点。但是你可以对download picture from url list in excel 进行网络搜索。 -> tipsformarketers.com/….

标签: excel vba download macros photo


【解决方案1】:

试试这个,看看你如何相处。

Sub ExportAllPictures()
    Dim MyChart As Chart
    Dim n As Long, shCount As Long
    Dim Sht As Worksheet
    Dim pictureNumber As Integer

    Application.ScreenUpdating = False
    pictureNumber = 1
    For Each Sht In ActiveWorkbook.Sheets
        shCount = Sht.Shapes.Count
        If Not shCount > 0 Then Exit Sub

        For n = 1 To shCount
            If InStr(Sht.Shapes(n).Name, "Picture") > 0 Then
                'create chart as a canvas for saving this picture
                Set MyChart = Charts.Add
                MyChart.Name = "TemporaryPictureChart"
                'move chart to the sheet where the picture is
                Set MyChart = MyChart.Location(Where:=xlLocationAsObject, Name:=Sht.Name)

                'resize chart to picture size
                MyChart.ChartArea.Width = Sht.Shapes(n).Width
                MyChart.ChartArea.Height = Sht.Shapes(n).Height
                MyChart.Parent.Border.LineStyle = 0 'remove shape container border

                'copy picture
                Sht.Shapes(n).Copy

                'paste picture into chart
                MyChart.ChartArea.Select
                MyChart.Paste

                'save chart as jpg
                MyChart.Export Filename:=Sht.Parent.Path & "\Picture-" & pictureNumber & ".jpg", FilterName:="jpg"
                pictureNumber = pictureNumber + 1

                'delete chart
                Sht.Cells(1, 1).Activate
                Sht.ChartObjects(Sht.ChartObjects.Count).Delete
            End If
        Next
    Next Sht
    Application.ScreenUpdating = True
End Sub

【讨论】:

    猜你喜欢
    • 2020-07-19
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多