我有一个包含许多产品图片的文件夹。每个产品有多个图像。我需要识别以我的产品编号(例如,100100)开头并以两个结尾“_FRONT”或“_ALTERNATE”之一结尾的那些。这两者之间还有其他信息。例如,文件名可以是 100100_headset_FRONT 或 100100_headset_SIDE。我希望它找到每个产品的正面或替代图像。
我已经成功地提取了图像,并且我认为我已经接近命名文件的方式,但并不完全在那里。代码返回错误“找不到指定的文件”
Sub PictureP()
Dim picname As String, picend As String
Dim PicPath As String
Dim lThisRow As Long
Dim Pic As Shape
Dim rngPic As Range
lThisRow = 3
Do While (Cells(lThisRow, 2) <> "")
Set rngPic = Cells(lThisRow, 1) 'This is where picture will be inserted
picname = Cells(lThisRow, 2) 'This is the picture name
picend = "_FRONT"
present = Dir("H:\Media\Images\1 Web Ready\Previews\" & picname & "*" & picend & ".jpg")
PicPath = ("H:\Media\Images\1 Web Ready\Previews\" & picname & "*" & picend & ".jpg")
If present <> "" Then
Set Pic = ActiveSheet.Shapes.AddPicture(PicPath, msoFalse, msoCTrue, 1, 1, -1, -1)
Else
Cells(lThisRow, 1) = ""
End If
lThisRow = lThisRow + 1
Loop
Range("B3").Select
On Error GoTo 0
Application.ScreenUpdating = True
Exit Sub
End Sub
代码返回错误“找不到指定的文件”