VBA使用相邻单元格中的URL下载和嵌入图像 [英] VBA download and embed images using url from adjacent cell

查看:85
本文介绍了VBA使用相邻单元格中的URL下载和嵌入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下尝试了解决方案.使用VBA将在线图片插入Excel

I've attempted the solution in the following. Inserting an Online Picture to Excel with VBA

不幸的是,我收到运行时错误"1004"无法获取Picture类的Insert属性"停止在以下代码上:

Unfortunately I get a run-time error '1004' "Unable to get the Insert property of the Picture class" which stops on the following code :

    Set myPicture = ActiveSheet.Pictures.Insert(pic)

这可能是由于我的Office版本2016(64位)引起的吗?如果没有,是否有关于如何使用AJ列中的图像网址将图像嵌入到AK列中相邻单元格的任何建议?

Could this be due to my Office version 2016 (64bit) ? If not, are there any suggestions of how I might get embed images to adjacent cells in column AK using the image urls from column AJ ?

预先感谢

推荐答案

@keydemographic

@keydemographic

我很感激您的回答,这听起来似乎是一个选择,但是我无法使该代码正常工作或将其合并到我正在使用的代码中.我在GoTo resumeProcessingImg上收到编译错误标签未定义"

I appreciate the response and that definitely sounds like an option but I cannot get that code to work or incorporate it into the code I'm using. I get a compile error "Label Not defined" on GoTo resumeProcessingImg

以下内容将下载图像并将其嵌入到单元格中,但是一旦到达s3 aws图像URL,代码就会停止.我将尝试其他几种方式来合并您的代码,但到目前为止,我对此不太满意.

The following will download and embed the images into the cells but the code stops once it gets to the s3 aws image urls. I'll try a few other ways to incorporate your code but I'm not having much luck with it so far.

这是我的测试文件

Sub URL2IMG() 
Dim pic As String 'path of pic
Dim myPicture As Picture 'embedded pic
Dim rng As Range 'range over which we will iterate
Dim cl As Range 'iterator

Set rng = Range("b2:b12")   '<~~ as needed, Modify range to where the images are to be embedded.
For Each cl In rng
pic = cl.Offset(0, -1)      '<~~ defines image link URL in column to the left of the embedded column
Set myPicture = ActiveSheet.Pictures.Insert(pic)

'you can play with the following to manipulate the size & position of the picture.
 With myPicture
    .ShapeRange.LockAspectRatio = msoFalse

    ' currently this shrinks the picture to fit inside the cell.
    .Width = cl.Width
    .Height = cl.Height
    .Top = Rows(cl.Row).Top
    .Left = Columns(cl.Column).Left

  End With

 Next

 End Sub

这篇关于VBA使用相邻单元格中的URL下载和嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆