excel - 嵌入以前使用 Pictures.Insert 插入的图像
问题描述
我已经构建了一个模板,可以帮助用户插入图像。
在 VBA 中,我使用了Pictures.insert,但是我随后发现此方法默认情况下会偷偷地将 LINK 插入到图像中,而不是嵌入它。显然,这意味着未连接到我们网络的第三方无法查看它。
所以,虽然我现在已经修复了模板,但已经设置好并填充了链接图像的各个文件夹中有几百个文件。
我认为我需要的是一个 VBA 脚本,它将遍历所选文件夹系统中每个可见工作簿中的每个工作表,并将所有链接的图像“转换”为嵌入的(nb。一些图像已手动插入,因此未链接)
我咨询了我的 IT 联系人并在线搜索了此处和其他地方,但找不到解决方案。
请问有人有什么想法吗?
附上简单的样品。 保存在 Google Drive 上的 ImageLink Excel 文档
这是我用来插入图像的代码,如果有帮助的话。生成 URL 的逻辑在电子表格中处理:
Sub InsertImage()
' This script inserts the image file referenced by the active cell
' Via https://www.extendoffice.com/documents/excel/4212-excel-insert-image-from-url.html
Dim Rng As Range
Dim filenam As String
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = Selection
Sheets("Sheet1").Range("activefile").Value = Rng.Value
filenam = Range("filenurl").Value
ActiveSheet.Pictures.Insert(filenam).Select
End Sub
解决方案
您可以复制图像并用粘贴的副本替换它们:
Sub Macro1()
Unlink ActiveSheet.Shapes(1)
End Sub
Sub Unlink(s)
Dim t, l, h, w, ws
With s
Set ws = .DrawingObject.Parent
t = .Top
l = .Left
h = .Height
w = .Width
.Copy
'might need to adjust the paste format...
ws.PasteSpecial Format:="Picture (PNG)", _
Link:=False, DisplayAsIcon:=False
End With
With ws.Shapes(ws.Shapes.Count)
.Top = t
.Left = l
.Height = h
.Width = w
End With
End Sub
推荐阅读
- java - 使用 Maven 发布插件从 pom 中排除依赖项?
- python - 需要从函数返回文件路径并将其作为参数传递给另一个函数
- java - 类似对象的序列化列表和字符串
- javascript - 如何将会话值发送到 PHP 中的 sql 查询中?
- swift - SwiftUI TextField 字距调整/跟踪?
- javascript - 尝试使用 axios 查询 API 端点
- javascript - 我如何将 setTimeout 与打字稿一起使用?
- ios - 使用 SDWebImages 时如何知道图像文件大小?
- uwp - 在 ARM 上的 Windows 10 上检测 UWP 应用仿真
- oracle - Oracle 数据库有什么功能可以将敏感数据指示器添加到列中?