Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

go up one folder level with FileSearch function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muyBN - 16 May 2006 00:26 GMT
With the FileSearch function, how would I instruct the .lookin field to
generically search a folder up one level relative to the folder which is
presently the default or operating folder?

Signature

Bryan

Helmut Weber - 16 May 2006 08:29 GMT
Hi Bryan,

have a look at this sample,
remembering good old DOS-times.

With Application.FileSearch
  .NewSearch
  .LookIn = "c:\test"
  MsgBox .LookIn
  .LookIn = ".." ' <<<
  MsgBox .LookIn
End With

Signature

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000

muyBN - 16 May 2006 09:34 GMT
Groovy, good old DOS. The irony is that many DB programs have gone back to
using command prompts. I never used the command prompt in SQL Server
7--pre.NET. I recall using one dot, .\ but never had the opportunity of using
double-dot. Thanks for letting me know; it worked perfectly.
Signature

Bryan

> Hi Bryan,
>
[quoted text clipped - 8 lines]
>    MsgBox .LookIn
> End With
muyBN - 16 May 2006 23:15 GMT
I should say that when I initially put your code into my function it worked
fine, but as I got into my function deeper, I could never get the search
folder to change.

First, here's a little explanation of what I'm trying to do, then the code
that doesn't accomplish it all:

(1) From a sub, I pass file name criteria (strFile = "201_P05*.*", for
example) and the path in which a certain instance of it is found.
(2) Search for instances of the file criteria within the folder.
(3) If more than one instance of the file criteria is found in a folder,
then the files in this folder are the ones I want to work with and blnStop is
set to true and the looping stops.
(4) On the other hand, if only one file in the searched folder fits the
search criteria, move up one folder level (attempted to do this per your
demonstration of ".."  but it didn't move to another folder).

This is my code:

Function umRefineIt(strFile As String, strPath As String) As String
   Dim strData As String, dirArray() As String, strFiles As String
   Dim intCnt As Integer, intFiles As Integer
   Dim blnStop As Boolean
   'declare initial size of array variable (shrink later)
   ReDim dirArray(1000)
   With Application.FileSearch
       .NewSearch
       .LookIn = strPath
       .SearchSubFolders = True
       .FileName = strFile
       .Execute
       intFiles = .FoundFiles.Count
       While .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) > 0 And blnStop = False
           If intFiles > 1 Then
               blnStop = True
               For intCnt = 1 To intFiles
                   If InStr(.FoundFiles(intFiles), "grading") = 0 Then
intFiles = intFiles + 1
               Next intCnt
           End If
           intCnt = 0
           .NewSearch
           .LookIn = strPath
           .LookIn = ".."
           .SearchSubFolders = True
           .FileName = strFile
           .Execute
       Wend
   End With
   .
   .
   .
   umRefineIt = strNewFile
End Function

I tried commenting out .NewSearch and changing .SearchSubFolders to false,
all without the desired results. Give it your magic touch, Helmut (if you see
this) or anyone who can graciously help me crack the code.
Signature

Bryan

> Hi Bryan,
>
[quoted text clipped - 8 lines]
>    MsgBox .LookIn
> End With
muyBN - 17 May 2006 05:40 GMT
Beautiful! I hereby answer my own question that I happened to see in Word VBA
help:

ChDir ".." takes you up one directory from where you are.
Signature

Bryan

> With the FileSearch function, how would I instruct the .lookin field to
> generically search a folder up one level relative to the folder which is
> presently the default or operating folder?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.