Excel VBA插入的图片现在是链接

我试图调整由以前的同事创build的代码失败。 我有非常有限的VBA经验,所以请裸露在我身边。 目前我们使用下面的代码。 它附加到Excel工作表上的一个button,它将图像插入指定范围的单元格中,调整图像大小,然后放在下面的单元格中input描述。 我们遇到的问题是我们的模板现在正从我们的服务器移到外面的位置。 所以所有的图像现在只是断开的链接。 我曾尝试根据其他职位进行调整,但都没有成功。

Private Sub Picture1_Click() ' Select Image From File With Application.FileDialog(msoFileDialogFilePicker) If .Show Then PicLocation = .SelectedItems(1) Else PicLocation = "" End If End With ' Error Check If PicLocation = "" Then MsgBox "No picture selected" Exit Sub End If 'Initialization Dim TargetCells As Range ActiveSheet.Unprotect Set TargetCells = Range("B9:H24") ' Error check 2 If PicLocation <> "False" Then Set p = ActiveSheet.Pictures.Insert(PicLocation) Else Exit Sub End If ' Set image dimensions With p.ShapeRange .LockAspectRatio = msoTrue .Height = TargetCells.Height If .Width > TargetCells.Width Then .Width = TargetCells.Width End With ' Set image location With p .top = TargetCells.top .Left = TargetCells.Left .PrintObject = True End With ' Close out operations Range("a25").Select Set p = Nothing 

结束小组

几年前,当切换Excel版本时,我遇到了同样的问题。 我的macros现在使用.Shapes.addPicture修改了下面的一段代码

 If PicLocation <> "False" Then Set p = ActiveSheet.Shapes.addPicture fileName:=PicLocation, linktofile:=False, savewithdocument:=True Else Exit Sub End If