Excel 如何将链接图像转换为嵌入图像?
我使用vba将文本替换为相应的图片。我稍微修改了代码(从),它工作得非常完美。然而,excel文件运行缓慢,即使我在执行后删除了模块(以防止每次打开文件时它都循环)。我的文件中大约有1000个图像。我想这可能是因为插入的图片仍然链接到外部文件夹。或者是因为其他原因,我只是宏vba的初学者,所以请指导我完成这项工作 我试过:Excel 如何将链接图像转换为嵌入图像?,excel,vba,image,Excel,Vba,Image,我使用vba将文本替换为相应的图片。我稍微修改了代码(从),它工作得非常完美。然而,excel文件运行缓慢,即使我在执行后删除了模块(以防止每次打开文件时它都循环)。我的文件中大约有1000个图像。我想这可能是因为插入的图片仍然链接到外部文件夹。或者是因为其他原因,我只是宏vba的初学者,所以请指导我完成这项工作 我试过: 卸下模块 优化文件(压缩图像等) 将粘贴复制到新列中 停用宏以确保它未运行 我的解决方案是(不确定是否有效): 将链接图像转换为嵌入图像 我在reddit上看到了这一点,如何
我在reddit上看到了这一点,如何将其实现到我的代码中?
activesheet.Shapes.AddPicture文件名:=“C:\test\desert.jpg”,链接文件:=msoFalse_
savewithdocument:=msoCTrue,左=0,顶=0,宽=100,高=100
以下是我在执行后使用和删除的代码:
子插入图片()
“乌帕代比H
将xPath设置为字符串
暗的和长的一样
变暗Rng As范围
变暗工作范围
出错时继续下一步
xTitleId=“KutoolsforExcel”
Set WorkRng=Application.Selection
设置WorkRng=Application.InputBox(“范围”,xTitleId,WorkRng.Address,类型:=8)
Application.ScreenUpdating=False
xPath=“C:\Users\vincenttan\Pictures\105APPLE\”
如果正确(xPath,1)“\”则xPath=xPath&“\”
xLastRow=单元格(Rows.Count,“A”).End(xlUp).Row
对于WorkRng中的每个Rng
如果Rng.Value为“”,则
如果Dir(xPath&Rng.Value&“.jpg”)”,那么
ActiveSheet.Pictures.Insert(xPath&Rng.Value&“.jpg”)。选择
带Selection.shaperage
.LockAspectRatio=msoFalse
.左=右左
.Top=Rng.Top
.Width=Rng.Width
.高度=平均高度
以
Rng.ClearContents
其他的
Rng.Value=“不适用”
如果结束
如果结束
下一个
Application.ScreenUpdating=True
端接头
i saw this on reddit how can i implement it into my code?
activesheet.Shapes.AddPicture Filename:="C:\test\desert.jpg", linktofile:=msoFalse, _
savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=100, Height:=100
Below are the code i used and removed after execution:
Sub InsertPicture()
'Upadateby H
Dim xPath As String
Dim xLastRow As Long
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
xPath = "C:\Users\vincenttan\Pictures\105APPLE\"
If Right(xPath, 1) <> "\" Then xPath = xPath & "\"
xLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For Each Rng In WorkRng
If Rng.Value <> "" Then
If Dir(xPath & Rng.Value & ".jpg") <> "" Then
ActiveSheet.Pictures.Insert(xPath & Rng.Value & ".jpg").Select
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Left = Rng.Left
.Top = Rng.Top
.Width = Rng.Width
.Height = Rng.Height
End With
Rng.ClearContents
Else
Rng.Value = "N/A"
End If
End If
Next
Application.ScreenUpdating = True
End Sub