presence76
03-01-2006, 06:35 PM
Sorry I could not come up with a better description.
I am reading a directory and creating 2 new ones, populating the new ones with the files from the first directory. When I get to the end of the files in the directory, it reads some files that I cannot see and begins to put them in the directories, producing a loop. The files have bizzarre names like "~$04370107B8B87B7C" and the text in them looks like
"
user1user1|Nn
\???d???????????????????????????
"
Code is:
Sub checkpages()
Dim fso As FileSystemObject
Dim fldr As Folder
Dim f As File
Dim myDoc As Document
Dim totpages As Integer
Dim onepagedir As String
Dim twopagedir As String
onepagedir = "P:\Clients\Vanguard\Finance\testing\onepagedocs\"
twopagedir = "P:\Clients\Vanguard\Finance\testing\twopagedocs\"
If Dir(onepagedir) <> "" Then
Kill (onepagedir)
End If
If Dir(twopagedir) <> "" Then
Kill (twopagedir)
End If
MkDir (onepagedir)
MkDir (twopagedir)
Const TARGET_FOLDER As String = "P:\Clients\Vanguard\Finance\testing\"
Set fso = New FileSystemObject
Set fldr = fso.GetFolder(TARGET_FOLDER)
For Each f In fldr.Files
If Right(f.Name, 4) = ".doc" Then
Set myDoc = Documents.Open(TARGET_FOLDER & f.Name)
totpages = Selection.Information(wdNumberOfPagesInDocument)
If totpages = 1 Then
myDoc.SaveAs FileName:=onepagedir & f.Name
myDoc.Close False
Else
If totpages = 2 Then
myDoc.SaveAs FileName:=twopagedir & f.Name
myDoc.Close False
End If
End If
End If
Next f
End Sub
It has to do with the For/Next loop. If anyone has any ideas, it would be greatly appreciated.
Thanks.
I am reading a directory and creating 2 new ones, populating the new ones with the files from the first directory. When I get to the end of the files in the directory, it reads some files that I cannot see and begins to put them in the directories, producing a loop. The files have bizzarre names like "~$04370107B8B87B7C" and the text in them looks like
"
user1user1|Nn
\???d???????????????????????????
"
Code is:
Sub checkpages()
Dim fso As FileSystemObject
Dim fldr As Folder
Dim f As File
Dim myDoc As Document
Dim totpages As Integer
Dim onepagedir As String
Dim twopagedir As String
onepagedir = "P:\Clients\Vanguard\Finance\testing\onepagedocs\"
twopagedir = "P:\Clients\Vanguard\Finance\testing\twopagedocs\"
If Dir(onepagedir) <> "" Then
Kill (onepagedir)
End If
If Dir(twopagedir) <> "" Then
Kill (twopagedir)
End If
MkDir (onepagedir)
MkDir (twopagedir)
Const TARGET_FOLDER As String = "P:\Clients\Vanguard\Finance\testing\"
Set fso = New FileSystemObject
Set fldr = fso.GetFolder(TARGET_FOLDER)
For Each f In fldr.Files
If Right(f.Name, 4) = ".doc" Then
Set myDoc = Documents.Open(TARGET_FOLDER & f.Name)
totpages = Selection.Information(wdNumberOfPagesInDocument)
If totpages = 1 Then
myDoc.SaveAs FileName:=onepagedir & f.Name
myDoc.Close False
Else
If totpages = 2 Then
myDoc.SaveAs FileName:=twopagedir & f.Name
myDoc.Close False
End If
End If
End If
Next f
End Sub
It has to do with the For/Next loop. If anyone has any ideas, it would be greatly appreciated.
Thanks.