excel - 如何让 "C"列中的图像 URL 在 Excel 中的 "N"列中显示其对应的图像?

标签 excel image vba

我有一个包含一堆列的 Excel 文件,其中之一是“ImageURL”,当然,它会将唯一的 URL 显示为文本。

我如何设置才能使这些图像也显示在另一列中?

我用过 following macro ,但我收到“无效的外部过程”编译错误。

Dim url_column As Range
Dim image_column As Range

Set url_column = Worksheets(1).UsedRange.Columns("C")
Set image_column = Worksheets(1).UsedRange.Columns("N")

Dim i As Long
For i = 1 To url_column.Cells.Count

  With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
    .Left = image_column.Cells(i).Left
    .Top = image_column.Cells(i).Top
    image_column.Cells(i).EntireRow.RowHeight = .Height
  End With

Next

不幸的是,我是 VBA 新手,所以也许我没有正确设置它?

最佳答案

好吧,这可能听起来很基本(没有双关语),但根据您提供的有限信息,我认为问题的原因是您只是将这些语句粘贴到代码模块中,而没有将它们在一个过程中。这肯定会给你一个“无效的外部过程”编译时错误。

您必须将一些东西放入过程中——要么是 Sub,要么是 Function。这种情况需要一个 Sub。试试这个:

Sub PlaceImageInCell()

    Dim url_column As Range
    Dim image_column As Range
    Set url_column = Worksheets(1).UsedRange.Columns("A")
    Set image_column = Worksheets(1).UsedRange.Columns("B")

    Dim i As Long
    For i = 1 To url_column.Cells.Count
      With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
        .Left = image_column.Cells(i).Left
        .Top = image_column.Cells(i).Top
        image_column.Cells(i).EntireRow.RowHeight = .Height
      End With
    Next

End Sub

关于excel - 如何让 "C"列中的图像 URL 在 Excel 中的 "N"列中显示其对应的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8345101/

相关文章:

excel - 编译错误: loop without do. But Do is in the code what is wrong?的代码

swift - 如何在swift中将UITableView数据导出到excel

Excel 突出显示重复项并按颜色替代进行过滤

vba - VB - 等待对象创建

c# - 异常 : Parameter is not valid (on passing new image to pictureBox)

javascript - 在 bPopup 中加载图像

excel - VBA - 如何更改按钮文本

具有查找值的 Excel sumif

android - picasso setIndicatorsEnabled(true) 不工作

vba - 如何在 VBA/Excel 中的用户定义函数中具有多个可选参数