Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用excel VBA在文件中查找上次更新的图片_Excel_Vba - Fatal编程技术网

如何使用excel VBA在文件中查找上次更新的图片

如何使用excel VBA在文件中查找上次更新的图片,excel,vba,Excel,Vba,我有以下脚本 Sub Picture() Dim picname As String Dim shp As Shape Dim pasteAt As Integer Dim lThisRow As Long Dim present As String Dim LastRow As Long Dim i As Long Dim PicCode As String LastRow = Cells(Rows.Count, 1

我有以下脚本

   Sub Picture()
    Dim picname As String
    Dim shp As Shape
    Dim pasteAt As Integer
    Dim lThisRow As Long
    Dim present As String
    Dim LastRow As Long
    Dim i As Long
    Dim PicCode As String
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
  

      Cells(1, 1).Resize(LastRow, 2).ColumnWidth = 20
      Cells(1, 1).Resize(LastRow, 2).RowHeight = 100
      Cells(1, 1).Resize(LastRow, 2).HorizontalAlignment = xlCenter
      Cells(1, 1).Resize(LastRow, 2).VerticalAlignment = xlCenter
      Set MyRange = Cells(1, 1).Resize(LastRow, 1)
       lThisRow = 1 'This is the start row
        Do While (Cells(lThisRow, 1) <> "")
            pasteAt = lThisRow
            Cells(pasteAt, 2).Select 'This is where picture will be inserted (column)
            picname = Cells(lThisRow, 1) 'This is the picture name
          

  present = Dir("C:\Users\User\Documents\albumForExcel\" & picname & ".jpg")
        If present <> "" Then
          Cells(pasteAt, 2).Select
           Call ActiveSheet.Shapes.AddPicture("C:\Users\User\Documents\albumForExcel\" & picname & 
          ".jpg", _
           msoCTrue, msoCTrue, Left:=Cells(pasteAt, 2).Left, Top:=Cells(pasteAt, 2).Top, Width:=100, 
      Height:=100).Select
            Else
            Cells(pasteAt, 2) = "No Picture Found"
       End If
        lThisRow = lThisRow + 1
    Loop
    Range("A1").Select
    Application.ScreenUpdating = True
    Exit Sub

  End Sub
子图片()
将picname设置为字符串
将shp变暗为形状
Dim pasteAt为整数
我的头发和你的一样长
以字符串的形式出现
最后一排一样长
我想我会坚持多久
将PicCode设置为字符串
LastRow=单元格(Rows.Count,1).End(xlUp).Row
单元格(1,1)。调整大小(最后一行,2)。列宽=20
单元格(1,1)。调整大小(LastRow,2)。行高=100
单元格(1,1)。调整大小(最后一行,2)。水平对齐=xlCenter
单元格(1,1)。调整大小(最后一行,2)。垂直对齐=xlCenter
设置MyRange=单元格(1,1)。调整大小(LastRow,1)
lThisRow=1'这是起始行
Do While(单元格(lThisRow,1)”)
pasteAt=lthislow
单元格(粘贴,2)。选择“这是插入图片的位置(列)”
picname=Cells(lThisRow,1)'这是图片名称
present=Dir(“C:\Users\User\Documents\albumForExcel\”&picname&“.jpg”)
如有,则
单元格(粘贴,2)。选择
调用ActiveSheet.Shapes.AddPicture(“C:\Users\User\Documents\albumForExcel\”&picname&
“.jpg”_
msoCTrue,msoCTrue,左:=单元格(粘贴,2)。左,顶部:=单元格(粘贴,2)。顶部,宽度:=100,
高度:=100)。选择
其他的
单元格(粘贴,2)=“未找到图片”
如果结束
lthistrow=lthistrow+1
环
范围(“A1”)。选择
Application.ScreenUpdating=True
出口接头
端接头
如果当前文件中不存在图片,我希望从备份文件导入图片。图片在备份文件中可能有多个实例。如何插入最后一个更新实例

谢谢


Dov

我不知道你的照片是如何存储的。“备份文件”到底是什么意思。哪种格式?图片存储为jpg文件,备份文件是一个系统文件夹,其中图片也存储为jpg文件。