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 / August 2006

Tip: Looking for answers? Try searching our database.

FileSearch

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
IA - 03 Aug 2006 10:03 GMT
I wrote several macros in Word 95 and 97 which were searching for files with
specific words in the file text, but I cannot convert them into Word 2003 or
write new macro in Word 2003 of this type. I cannot insert words for  search
into the "text or property" property in the FileSearch object:

With Application.FileSearch
     .NewSearch
     .FileType = msoFileTypeOfficeFiles
      .Text Or Property = ???
           .LookIn = Directory
     .Execute

In a way to search for files which contains several keywords. For instance,
I have to find all files in a directory which contains words "bread",
"butter" and "pepper".

In the early versions of Word Basic it was enough to insert "&" between the
search  words, but I do not understand how to make it in Word 2003.
I tryed to record macro from screen, but Word 2003 display empty window
after recording such macro. I cannot use earlier version of Word, because
they cannot open .htm files without frequent crashes.
I make my life money with  searching files in Word, and I am currently  in
the dead end. I am not a programmer, but live forced me to do the simple
things with macro.
Please, if somebody has an idea, help me.

Petr Dombrovski, Graz
Ed - 03 Aug 2006 15:55 GMT
I have a FileSearch macro I use in through Excel to search through Word
documents for up to three words in the document text.  It's working in
Excel/Word 2002.  I build a search string something like this:
  strWord1 = "bread"
  strWord2 = "butter"
  strWord3 = "pepper"
  strSearch = strWord1 & " and " & strWord2 & " and "  & strWord3

Then the FileSearch part looks something like:
   With Application.FileSearch
       .NewSearch
       .LookIn = strLocation
       .SearchSubFolders = False
       .TextOrProperty = strSearch
       .Filename = "*.doc"
       .Execute
   End With

HTH
Ed

>I wrote several macros in Word 95 and 97 which were searching for files
>with
[quoted text clipped - 28 lines]
>
> Petr Dombrovski, Graz
IA - 03 Aug 2006 17:39 GMT
Ed,

thanks, I shall immediately try it and inform you about results

Petr
> I have a FileSearch macro I use in through Excel to search through Word
> documents for up to three words in the document text.  It's working in
[quoted text clipped - 49 lines]
> >
> > Petr Dombrovski, Graz
IA - 03 Aug 2006 18:15 GMT
Ed,
it for some reasons does not work in my script. Can you kindly send me the
relevant piece of code to the Idombr@Gmail.com? I shall try to realize, what
is going wrong in my code.
Thanks in advance,
Petr.

> I wrote several macros in Word 95 and 97 which were searching for files with
> specific words in the file text, but I cannot convert them into Word 2003 or
[quoted text clipped - 23 lines]
>
>  Petr Dombrovski, Graz
Ed - 03 Aug 2006 20:50 GMT
Petr - It would be much better for you to post the code you are using and
the environment you are running in.  Please include how you set up your
search string and any other strings used in the search code.  (If you want,
just post the whole thing.)  I am not the best person here by any means, but
if you and I do this only be email, then all you get is my knowledge, which
is very little compared to most who come here.  If you keep everything in
the newsgroup, you can get input from the experts - there is a great wealth
of education and experience here (just not all behind _my_ keyboard!).

Ed

> Ed,
> it for some reasons does not work in my script. Can you kindly send me the
[quoted text clipped - 3 lines]
> Thanks in advance,
> Petr.

>> I wrote several macros in Word 95 and 97 which were searching for files
> with
[quoted text clipped - 29 lines]
>>
>>  Petr Dombrovski, Graz
IA - 04 Aug 2006 01:31 GMT
Ed,
thanks for your advice/

I use the following code in MS Office 2003/SP-2/WinXP SP-2:
Sub Moltest()

' Moltest Macro
' Macro created 02.08.2006 by IA
'Dim x, y, z As String, MyName As String
  Dim i As Integer
  Dim Response As Integer, TotalFiles As Integer

  On Error Resume Next

Folder:

  ' Prompt the user for the folder to list.
 X = InputBox(Prompt:="What folder do you want to list?" & vbCr & vbCr _
        & "For example: C:\My Documents", _
        Default:="G:\Docart")

 y = InputBox(Prompt:="What files do you want to look for?" & vbCr & vbCr _
        & "For example: *.doc", _
        Default:="*.doc; *.htm; *.txt")

 Z = InputBox(Prompt:="Insert keywords" & vbCr & vbCr _
        & "For example: Reactor And nuclear")

  If X = "" Or X = " " Or y = "" Or y = " " Or Z = "" Or Z = " " Then
     If MsgBox("Either you did not type a text correctly" _
           & vbCr & "or you clicked Cancel. Do you want to quit?" _
           & vbCr & vbCr & _
           "If you want to type once more, click No." & vbCr & _
           "If you want to quit, click Yes.", vbYesNo) = vbYes Then
        Exit Sub
     Else
        GoTo Folder
     End If
  End If

  ' Test if folder exists.
  If Dir(X, vbDirectory) = "" Then
     MsgBox "The folder does not exist. Please try again."
     GoTo Folder
  End If

  ' Search the specified folder for files
  ' and type the listing in the document.
  With Application.FileSearch
     .NewSearch
     .FileType = y
     ' Change the .FileType to the type of files you are looking for;
     ' for example, the following line finds all files:
     ' .FileType = msoFileTypeAllFiles
     .SearchSubFolders = True
   .FileName = ""
   .MatchTextExactly = False
   .TextOrProperty = Z
     .LookIn = X
     .Execute
     TotalFiles = .FoundFiles.Count
     If TotalFiles = 0 Then
        MsgBox ("There are no files in the folder!" & _
              "Please type another folder to list.")
        GoTo Folder
     End If

     ' Create a new document for the file listing.
     Application.Documents.Add
     ActiveDocument.ActiveWindow.View = wdPrintView

     ' Set tabs.
     With Selection.ParagraphFormat.TabStops
        .Add _
              Position:=InchesToPoints(3), _
              Alignment:=wdAlignTabLeft, _
              Leader:=wdTabLeaderSpaces
        .Add _
              Position:=InchesToPoints(4), _
              Alignment:=wdAlignTabLeft, _
              Leader:=wdTabLeaderSpaces
     End With

     ' Type the file list headings.
     Selection.TypeText "File Listing of the "

     With Selection.Font
        .AllCaps = True
        .Bold = True
     End With
     Selection.TypeText X
     With Selection.Font
        .AllCaps = False
        .Bold = False
     End With
     Selection.TypeText " folder!" & vbLf
     Selection.Font.Underline = wdUnderlineSingle
     Selection.TypeText vbLf & "File Name" & vbTab & "File Size" _
           & vbTab & "File Date/Time" & vbLf & vbLf
     Selection.Font.Underline = wdUnderlineNone
     For i = 1 To TotalFiles
        MyName = .FoundFiles(i)
        Selection.TypeText MyName & vbTab & FileLen(MyName) _
              & vbTab & FileDateTime(MyName) & vbLf
     Next i

     ' Type the total number of files found.
     Selection.TypeText vbLf & "Total files in folder = " & TotalFiles & _
           " files."
  End With

  MsgBox ("The number of files is " & TotalFiles & _
           " files.")

  If MsgBox("Do you want to list another folder?", vbYesNo) = vbYes Then
     GoTo Folder2
     Else
     GoTo Konets1
  End If
Folder2:

Konets1:

End Sub

If I use the first keyword, it is about 1000 files in TotalFiles, with
second it become 3000 and with third - 6000.
It looks like instead of AND code uses OR function, and I do not realize,
why it happens

Petr.

> Petr - It would be much better for you to post the code you are using and
> the environment you are running in.  Please include how you set up your
[quoted text clipped - 48 lines]
> >>
> >>  Petr Dombrovski, Graz
 
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.