Wild card in filepath

E

ephelps

i'm using office 2003 and trying to paste an image from a file. The
actual image name is constant, "theone.jpg" but the actual subfolder
is different and is something like "c:\documents\data\232 - 123 Sesame
St\pictures\." The name of the subfolder "232 - 123 Sesame St" is
variable. I want to be able to insert the picture using a wild card
such as "c:\documents\data\232 * \pictures\" but that returns in
error. What is the correct way to insert a wild card in the file path?

Here is the code I have so far that isn't working:
Sub Macro1()

Dim mypath As String
Dim filename As String
Dim fullpath As String

filename = "theone.jpg"
mypath = "c:\documents\data\232 * \pictures\"
MsgBox (mypath)
Selection.InlineShapes.AddPicture (mypath & filename)
End Sub
 
J

Joel

Use filesearch as explained in VBA help below

Sub findpicture()

mypath = "c:\documents\data\232"
With Application.FileSearch
.NewSearch
.LookIn = mypath
.SearchSubFolders = True
.filename = "theone.jpg"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles

If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If

End With
' the line below is commented
' Selection.InlineShapes.AddPicture (mypath & filename)

End Sub



Using the FileSearch Object
Use the FileSearch property to return the FileSearch object. The following
example searches for files and displays the number of files found and the
name of each file.

With Application.FileSearch
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
Use the NewSearch method to reset the search criteria to the default
settings. All property values are retained after each search is run, and by
using the NewSearch method you can selectively set properties for the next
file search without manually resetting previous property values. The
following example resets the search criteria to the default settings before
beginning a new search.

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = True
.FileName = "Run"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top