我想做的不仅仅是从文件中获取图片。我需要做到这一点,以便一个人可以只上传6张照片的文件夹,宏将做它的事情。无论文件名如何。这有什么类似索引值的东西吗?我可以按照他们的位置定义图片吗?
我在想:
Sub PicturePull ()
Dim Pic as Integer
DimPicName as String
PicName = >>?!?!?!?!<<
Pic = 1
Do while Pic < 7
Selection.InlineShapes.AddPicture FileName:= _
"\\agcfp01\users\cjones\desktop\Russells Template\Thermography Photos\Real\" & PicName _
, LinkToFile:=False, SaveWithDocument:=True
Pic= Pic + 1
Loop
End Sub
答案 0 :(得分:1)
这对我有用:
Sub PicturePull()
Dim SourceFolder As String
Dim i As Integer, PicName As String
SourceFolder = "C:\Users\ggggg\Desktop\Pictures\"
i = 0
PicName = Dir(SourceFolder & "*")
'or (eg)
'PicName = Dir(SourceFolder & "*.jpg") 'jpg only...
Do While Len(PicName) > 0
i = i + 1
If i > 6 Then Exit Do
Selection.InlineShapes.AddPicture FileName:=SourceFolder & PicName, _
LinkToFile:=False, SaveWithDocument:=True
PicName = Dir()
Loop
End Sub