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 / December 2004

Tip: Looking for answers? Try searching our database.

FileSearch

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jaysfive - 14 Dec 2004 15:37 GMT
How would I change this to search for files begining with a set letter

With Application.FileSearch
.FileName = "*.doc"
.LookIn = "G:\a_a_e"
.MatchTextExactly = True
.SearchSubFolders = False
       .Execute
Jean-Guy Marcil - 14 Dec 2004 15:56 GMT
jaysfive was telling us:
jaysfive nous racontait que :

> How would I change this to search for files begining with a set letter
>
[quoted text clipped - 4 lines]
> .SearchSubFolders = False
>        .Execute

> .FileName = "*.doc"
should be
   .FileName = "S*.doc"
if the set letter is "S".

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

jaysfive - 14 Dec 2004 16:06 GMT
No, this finds all files with an "S" anywhere in the filename
Andi Mayer - 14 Dec 2004 18:44 GMT
>No, this finds all files with an "S" anywhere in the filename

You are sure????? *S* finds all S, but S* finds only the beginning, at
least on my Computers

If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
jaysfive - 14 Dec 2004 23:07 GMT
> >No, this finds all files with an "S" anywhere in the filename
>
[quoted text clipped - 3 lines]
> If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
> MW

Hope you don't object Manfred but here is the full macro:-
Sub ChangeTemplateToNormal()

Dim killFile As String
Dim myCopy  As Document
Dim docName As String
Dim oForm As Object
Dim i As Integer
Dim varFile As Variant
With Application.FileSearch
.NewSearch
.FileName = "d*.doc"
.LookIn = "G:\a_a_e"
.SearchSubFolders = False
.Execute

For Each varFile In .FoundFiles
With Documents.Open(FileName:=varFile,
ConfirmConversions:=False)
On Error GoTo z
.UpdateStylesOnOpen = False
On Error GoTo z
.AttachedTemplate = "normal"
On Error GoTo z
.Save
.Close savechanges:=wdSaveChanges
Application.StatusBar = varFile
Close
End With
u:

Next varFile
End With
GoTo x
'Application.StatusBar = varFile
z:

'+++++++++++++++++++++++++++++++++++++++++++++++++++++
MsgBox "Bad document,click OK, see next message box for document
name,move it somewhere else and run macro again"
MsgBox varFile
Application.StatusBar = varFile
x:

Call macro_finished
Application.Quit savechanges:=wdPromptToSaveChanges
End Sub

This finds "abdner.doc
jaysfive - 14 Dec 2004 23:16 GMT
> >No, this finds all files with an "S" anywhere in the filename
>
[quoted text clipped - 3 lines]
> If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
> MW

Hope you don't object Manfred but here is the full macro:-
Sub ChangeTemplateToNormal()

Dim killFile As String
Dim myCopy  As Document
Dim docName As String
Dim oForm As Object
Dim i As Integer
Dim varFile As Variant
With Application.FileSearch
.NewSearch
.FileName = "d*.doc"
.LookIn = "G:\a_a_e"
.SearchSubFolders = False
.Execute

For Each varFile In .FoundFiles
With Documents.Open(FileName:=varFile,
ConfirmConversions:=False)
On Error GoTo z
.UpdateStylesOnOpen = False
On Error GoTo z
.AttachedTemplate = "normal"
On Error GoTo z
.Save
.Close savechanges:=wdSaveChanges
Application.StatusBar = varFile
Close
End With
u:

Next varFile
End With
GoTo x
'Application.StatusBar = varFile
z:

'+++++++++++++++++++++++++++++++++++++++++++++++++++++
MsgBox "Bad document,click OK, see next message box for document
name,move it somewhere else and run macro again"
MsgBox varFile
Application.StatusBar = varFile
x:

Call macro_finished
Application.Quit savechanges:=wdPromptToSaveChanges
End Sub

This finds "abdner.doc
Andi Mayer - 15 Dec 2004 10:07 GMT
>Hope you don't object Manfred but here is the full macro:-

I would use a total different aproach:

Sub Manfred_ChangeTemplateToNormal()
Dim FileName as string
FileName=Dir("G:\a_a_e\d*.doc")
Do While FileName<>""
 'Do your Document stuff here
 FileName=Dir
loop

If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
jaysfive - 14 Dec 2004 23:20 GMT
> >No, this finds all files with an "S" anywhere in the filename
>
[quoted text clipped - 3 lines]
> If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
> MW

Hope you don't object Manfred but here is the full macro:-
Sub ChangeTemplateToNormal()

Dim killFile As String
Dim myCopy  As Document
Dim docName As String
Dim oForm As Object
Dim i As Integer
Dim varFile As Variant
With Application.FileSearch
.NewSearch
.FileName = "d*.doc"
.LookIn = "G:\a_a_e"
.SearchSubFolders = False
.Execute

For Each varFile In .FoundFiles
With Documents.Open(FileName:=varFile,
ConfirmConversions:=False)
On Error GoTo z
.UpdateStylesOnOpen = False
On Error GoTo z
.AttachedTemplate = "normal"
On Error GoTo z
.Save
.Close savechanges:=wdSaveChanges
Application.StatusBar = varFile
Close
End With
u:

Next varFile
End With
GoTo x
'Application.StatusBar = varFile
z:

'+++++++++++++++++++++++++++++++++++++++++++++++++++++
MsgBox "Bad document,click OK, see next message box for document
name,move it somewhere else and run macro again"
MsgBox varFile
Application.StatusBar = varFile
x:

Call macro_finished
Application.Quit savechanges:=wdPromptToSaveChanges
End Sub

This finds "abdner.doc
Helmut Weber - 14 Dec 2004 22:15 GMT
Hi,
yes, you are right,
here and now, according to my specifications,
First point, filesearch returns the fullname,
like "c:\test\test.mydoc.doc"

Second point, it returns fullnames,
that contain an "S" or "s", unexpectedly,
and I don't know about case sensitivity here,
it is a mystery.

So, try this one:

Sub Makro2()
Dim l As Long
Dim s As String
With Application.FileSearch
   .FileName = "S*.doc"
   .LookIn = "c:\"
   .SearchSubFolders = True
   .Execute
For l = 1 To .FoundFiles.Count
  s = StrReverse(.FoundFiles(l))
  s = Left(s, InStr(s, "\"))
  s = Left(s, Len(s) - 1)
  s = StrReverse(s)
  If Left(s, 1) = "s" Or Left(s, 1) = "S" Then
     Selection.TypeText s & vbCr
  End If
Next
End With
End Sub

If you need help for putting the result into an array,
ask again.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
jaysfive - 15 Dec 2004 13:51 GMT
> Hi,
> yes, you are right,
[quoted text clipped - 37 lines]
> Word XP, Win 98
> http://word.mvps.org/

Many thanks Helmut, since I'm a 67 year old pensioner without a lot of
knowledge of vba and trying to help my daughter with WORD may I push my
luck and ask you how I would insert your sub into:--

Sub ChangeTemplateToNormal()
Call macro_running
'Application.DisplayAlerts = False
'AnimateScreenMovements = False
'ScreenUpdating = False
'Application.Visible = False
Dim oForm As Object
Dim i As Integer
'    Dim i As Long
Dim varFile As Variant
'UserForm1.Show
With Application.FileSearch
'*** select files ********************************

.FileName = "*.doc"
.LookIn = "\\server2\cvs\L_R"
.SearchSubFolders = False
.Execute

For Each varFile In .FoundFiles
With Documents.Open(FileName:=varFile,
ConfirmConversions:=False)
On Error GoTo z
.UpdateStylesOnOpen = False
.AttachedTemplate = "normal"
.Save
.Close SaveChanges:=wdSaveChanges
'Application.StatusBar = varFile
Close
End With
qq:
Next varFile
End With
GoTo x
'Application.StatusBar = varFile

ScreenUpdating = True
AnimateScreenMovements = False
Application.Visible = True
z:
MsgBox "Bad document,click OK, see next message box for document
name,move it somewhere else and run macro again"
MsgBox varFile

GoTo qq
Application.StatusBar = varFile
x:
'Unload UserForm1
Call macro_finished
Application.Quit SaveChanges:=wdPromptToSaveChanges

End Sub
Helmut Weber - 15 Dec 2004 16:55 GMT
Hi Jaysfive,
if you have read the other postings,
you know, that this was thrilling:
Didn't know, whether I was wrong or right,
but hopefully, I got it. It's like this:

Sub Gotcha()
Dim i As Integer
Dim s As String
With Application.FileSearch
   .FileName = "s*.doc"
   .LookIn = "c:\"
   .MatchTextExactly = True
   .SearchSubFolders = True
   .Execute
  For i = 1 To .FoundFiles.Count
     s = StrReverse(.FoundFiles(i))
     ' seems to be case sensitive after all
     If Mid(s, InStr(s, "\") - 1, 1) = "s" Or _
        Mid(s, InStr(s, "\") - 1, 1) = "S" Then
        ' your code goes into here, like
        ' with
        ' Documents.Open(FileName:=.FoundFiles(i),
        ' ConfirmConversions:=False) etc. etc.
        ' next line is for testing only
        Selection.TypeText .FoundFiles(i) & vbCr
     End If
  Next
End With
End Sub

If you need some comment on StrReverse or the mid-thing,
don't hesitate to ask again.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
jaysfive - 15 Dec 2004 18:38 GMT
Not sure if I should be pleased or not at raising the issue, but as
long as you guys enjoyed yourselves, I can't complain. I certainly
appreciate your help. Many thanks Helmut and Jean-Guy. A word of
warning - if I need more help, I shall return

jeff
jaysfive - 15 Dec 2004 19:57 GMT
It works - YIPEE.
You've just saved me having to change templates on 27,000 CVs
Salut!  &  Vielen Dank!
regards
non foreign language speaking Scotsman
jaysfive - 15 Dec 2004 20:03 GMT
It works - YIPEE.
You've just saved me having to change templates on 27,000 CVs
Salut!  &  Vielen Dank!
regards
non foreign language speaking Scotsman
Jean-Guy Marcil - 15 Dec 2004 01:33 GMT
jaysfive was telling us:
jaysfive nous racontait que :

> No, this finds all files with an "S" anywhere in the filename

There is something wrong with your version or there is a bug in the version
you are using.

Here  with Office 2003 SP1 on WinXP Pro SP2, the following
'_______________________________________
   With Application.FileSearch
       .FileName = "*.*"
       .LookIn = "C:\Windows"
       .MatchTextExactly = True
       .SearchSubFolders = False
       .Execute
       For i = 1 To .FoundFiles.Count
           MsgBox .FoundFiles(i)
       Next
   End With
'_______________________________________
returns 107 files.

On the other hand,
'_______________________________________
   With Application.FileSearch
       .FileName = "c*.*"
       .LookIn = "C:\Windows"
       .MatchTextExactly = True
       .SearchSubFolders = False
       .Execute
       For i = 1 To .FoundFiles.Count
           MsgBox .FoundFiles(i)
       Next
   End With
'_______________________________________
returns 8 files, the only 8 in the folder that start with "c".
And capitalization is not an issue,
         .FileName = "C*.*"
returns the same 8 files.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Helmut Weber - 15 Dec 2004 16:01 GMT
Hi Jean-Guy,

I had omitted  .MatchTextExactly = True
With it, everything works as expected.
Wasn't my day, it seems.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Helmut Weber - 15 Dec 2004 16:23 GMT
Hi Jean-Guy,
still one of these days...
Have a very close look at:

Sub NoGood()
Dim i As Integer
With Application.FileSearch
   .FileName = "s*.doc"
   .LookIn = "c:\"
   .MatchTextExactly = True
   .SearchSubFolders = True
   .Execute
  For i = 1 To .FoundFiles.Count
     Selection.TypeText .FoundFiles(i) & vbCr
  Next
End With
End Sub

and

Sub Alright()
Dim i As Integer
  With Application.FileSearch
       .FileName = "s*.*"
       .LookIn = "c:\"
       .MatchTextExactly = True
       .SearchSubFolders = True
       .Execute
       For i = 1 To .FoundFiles.Count
           Selection.TypeText .FoundFiles(i) & vbCr
       Next
   End With
End Sub

Did you try it? It's amazing!

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/

>jaysfive was telling us:
>jaysfive nous racontait que :
[quoted text clipped - 36 lines]
>          .FileName = "C*.*"
>returns the same 8 files.
Jean-Guy Marcil - 15 Dec 2004 16:47 GMT
Helmut Weber was telling us:
Helmut Weber nous racontait que :

> Hi Jean-Guy,
> still one of these days...
[quoted text clipped - 31 lines]
>
> Did you try it? It's amazing!

Amazing is not the word... more like "depressing"...

So there is a bug when we use
   SearchSubFolders = True
and that we want specific file extensions...
(If you set SearchSubFolders to false, then it works as expected in both
cases, this means that MatchTextExactly  has nothing to do with it).

Thanks, good to know... This means we need to implement some kind of
workaround...At least, by now, we are used to this!

Cheers!

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Rate this thread:






 
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.