Parachute Woman was telling us:
Parachute Woman nous racontait que :
> Hi, I have been trying unsucessfully to manipulate the following code
> for my purposes. Could anyone please help? I am trying to loop
[quoted text clipped - 7 lines]
> dealing with a few hundred applications, so pressing two buttons
> everytime will be quite tedious.
You had some problems mainly because:
ActiveDocument.SaveAs FileName:=ActiveDocument.Name, _
FileFormat:=wdFormatText, SaveFormsData:=True
ActiveWindow.Close
If you specify a different file format (.txt) but give Word a "*.doc" name
(ActiveDocument.Name), Word will create a doc file, not a txt file.
It is also bad practice to rely on ActiveDocument and ActiveWindow to point
to the right place when dealing with multiple documents. Always use Document
objects. See my code, I use 3 document objects so when I write the code I
always know which document I am dealing with.
Also, for the mostly same reason, avoid using the selection object.
> 2) Error - cannot save forms data as the same name as active document
> ... my text files need to be of the same name!
Already answered above.
Also, your code as it was would not have opened the txt files. You got that
far because you were creating doc files instead of txt files.
This is why I added:
.FileName = "*.txt"
Otherwise, Application.FileSearch use the current setting in the user Open
Dialog setting.
Finally, see how I record the user preferred setting for confirming
conversion, then change it to my need and finally set it back to its
original setting (Which may or may not have been the same), also notice how
I did not use the Selection object to get the text form the txt file into
the main file.
'_______________________________________
Sub CompileFormData()
Const strDir As String = "X:\Office 2003"
Const strDirTest As String = strDir & "\Test"
Dim i As Integer
Dim Doc As Document
Dim CurDoc As Document
Dim TextDoc As Document
Dim boolUserOpenFormat As Boolean
boolUserOpenFormat = Options.ConfirmConversions
Set CurDoc = ActiveDocument
With Application.FileSearch
.NewSearch
.LookIn = strDir
.SearchSubFolders = False
If .Execute() > 0 Then
ChangeFileOpenDirectory strDirTest
For i = 1 To .FoundFiles.Count
Set Doc = Documents.Open(.FoundFiles(i))
With Doc
.SaveFormsData = True
.SaveAs FileName:=Left(.Name, Len(.Name) - 4) & ".txt", _
FileFormat:=wdFormatText, SaveFormsData:=True
.Close
End With
Next i
End If
End With
With Application.FileSearch
.NewSearch
.LookIn = strDirTest
.SearchSubFolders = False
.FileName = "*.txt"
If .Execute() > 0 Then
Options.ConfirmConversions = False
For i = 1 To .FoundFiles.Count
Set TextDoc = Documents.Open(.FoundFiles(i))
CurDoc.Range.InsertAfter TextDoc.Range.Text & vbCrLf
TextDoc.Close
Next i
Options.ConfirmConversions = boolUserOpenFormat
End If
End With
End Sub
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Parachute Woman - 16 Mar 2006 10:49 GMT
Thats absolutely brilliant! Many thanks for explaining your solution
so clearly.
Jean-Guy Marcil - 16 Mar 2006 16:49 GMT
Parachute Woman was telling us:
Parachute Woman nous racontait que :
> Thats absolutely brilliant! Many thanks for explaining your solution
> so clearly.
No problem, glad I could help.
I forgot to mention one tiny detail.... this is a userform group (for things
that look like dialog boxes), so you should have posted in the vba.general
group instead...
Just thought I'd let you know!

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