Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Wild card in filepath

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Wild card in filepath

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


" wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wild Card Search fi.or.jp.de Excel Worksheet Functions 2 August 3rd 09 07:56 PM
VLOOKUP with Wild Card? RoadKill Excel Worksheet Functions 2 February 29th 08 06:14 PM
wild card in sumproduct BNT1 via OfficeKB.com Excel Worksheet Functions 3 November 26th 07 04:10 AM
Wild Card!!!??? Sean Excel Programming 3 August 31st 06 06:55 PM
Wild card * Herman Excel Worksheet Functions 0 October 21st 05 01:39 PM


All times are GMT +1. The time now is 02:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"