0
  1. I have this code:

    Sub InsertPhotos_Click()
        Range("Photo1").Select
        ActiveSheet.Pictures.Insert("U:\Trial\1.jpg").Select
        Selection.ShapeRange.Height = 151.2
        Selection.ShapeRange.IncrementLeft 27
        Selection.ShapeRange.IncrementTop 3
    End Sub
    

I need to be able to name the filename 1-xxxx, but not sure how to use a wildcard. When the filename is 1, the code does what I want it to. Any help would be great, thanks!

Community
  • 1
  • 1
Carrie
  • 1
  • 3
  • You meant like to rename files? Or additional files that you want to get follow the format 1-xxxx? – Sgdva Jul 13 '16 at 17:09
  • I want the user to be able to name the file 1-(filename), e.g. 1-up close photo. Then I need the code to recognize the 1- and choose that file, no matter what comes after the "-". I tried ("U:\Trial\1- & "*".jpg") without success. – Carrie Jul 13 '16 at 18:23

1 Answers1

0

Does this work?

Sub InsertPhotos_Click()
Dim PhotoString As String
    Range("Photo1").Select
    PhotoString = Application.InputBox("Type text for picture", "Get Picture", Type:=2)
    If PhotoString <> "" Then ' 1. If PhotoString <> ""
    ActiveSheet.Pictures.Insert("U:\Trial\1-" & PhotoString & ".jpg").Select
    Selection.ShapeRange.Height = 151.2
    Selection.ShapeRange.IncrementLeft 27
    Selection.ShapeRange.IncrementTop 3
    End If ' 1. If PhotoString <> ""
End Sub
Sgdva
  • 2,800
  • 3
  • 17
  • 28
  • Yes, that works, but I am going to be inserting 10+ photos, I want them all to be named 1-(filename); 2-(filename); etc. I just want it to pull the file based on the first two characters of the filename with a wildcard. Not sure if possible... – Carrie Jul 14 '16 at 12:54
  • Please explain, first you said you wanted the user being able to name the file and now you want them automatically named? What filename would be? (if picture is named 1; 1-1?) – Sgdva Jul 14 '16 at 13:29
  • I have 8 users naming the files. I just want them all to name their first photo 1-(something). Then I want the code to pull the photo that starts with 1-. They will all be named, however the name will be different each time, depending on what the photo is, except they will all start 1-. – Carrie Jul 14 '16 at 15:04
  • You would need to loop through files in the folder then, take a look at this [question](http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba) – Sgdva Jul 14 '16 at 15:42
  • Sorry, I don't follow – Carrie Jul 14 '16 at 17:38