lazyuser
02-24-2009, 12:09 PM
i am working on a batch application where i need to open word documents in a folder(specified folder), check for word documents, open a copy of the document, iinsert some links into it and then save this copy with a prefix "NEW_". my tool keeps doing this for all the word documents until there are not more documents left in the folder.
all this works fine, however, i need to skip a document that already has a "NEW_" prefix. just skip that document and pick up the next document without the prefix.
i am able to trap this. but how do i continue from there?
this is my code if you need it...
If (objFSO.FolderExists(txtSourceFolder.Text)) Then
Set objfolder = objFSO.GetFolder(txtSourceFolder.Text)
If objfolder.Files.Count = 0 Then 'check to see if any files exist in the folder
MsgBox "There are no documents to be processed in this folder!", vbOKOnly, appName
Exit Sub
Else
MsgBox "There are " & objfolder.Files.Count & " files in this folder.", vbOKOnly, appName
For Each objFile In objfolder.Files
If Word.Documents.Count > 0 Then
If Right(UCase(objFile.Name), 4) = ".DOC" Then 'check for files ending with .doc extension
If Left(UCase(objFile.Name), 4) = "NEW_" Then
MsgBox "IGNORE THIS FILE"
Exit Sub
Else
Word.Documents.Open (objFile.Path)
FindCitations
Set objDoc = Documents(Documents.Count - 1)
If objDoc Is Nothing Then 'counter keeps track of how the number of documents being processed
docCount = 0
Else
docCount = docCount + 1
End If
If Not objDoc Is Nothing Then 'saving the processed document with the prefix "NEW_"
objDoc.SaveAs (txtDestinationFolder.Text & "NEW_" & objFile.Name)
objDoc.Close
End If
If Documents.Count > 0 Then
Set objDoc = Documents(Documents.Count - 1)
If Not objDoc Is Nothing Then
objDoc.Close
End If
End If
End If
Else
MsgBox "No Word Documents exist in selected folder.", vbOKOnly, appName
Exit Sub
End If 'end check for documents ending with .doc extension
Else
MsgBox "No Documents exist in selected folder.", vbOKOnly, appName
End If
Next
End If 'end check to see if any files exist in the folder.
Else
MsgBox "Specified folder does not exist. Please choose a valid folder.", vbOKOnly, appName
txtDestinationFolder.SetFocus
Exit Sub
End If
MsgBox docCount & " Documents have been processed successfully!", vbOKOnly, appName
obviously, i cannot say end or exit sub here as this would take me out of the application.
help will be greatly appreciated. its quite urgent. thankssss
all this works fine, however, i need to skip a document that already has a "NEW_" prefix. just skip that document and pick up the next document without the prefix.
i am able to trap this. but how do i continue from there?
this is my code if you need it...
If (objFSO.FolderExists(txtSourceFolder.Text)) Then
Set objfolder = objFSO.GetFolder(txtSourceFolder.Text)
If objfolder.Files.Count = 0 Then 'check to see if any files exist in the folder
MsgBox "There are no documents to be processed in this folder!", vbOKOnly, appName
Exit Sub
Else
MsgBox "There are " & objfolder.Files.Count & " files in this folder.", vbOKOnly, appName
For Each objFile In objfolder.Files
If Word.Documents.Count > 0 Then
If Right(UCase(objFile.Name), 4) = ".DOC" Then 'check for files ending with .doc extension
If Left(UCase(objFile.Name), 4) = "NEW_" Then
MsgBox "IGNORE THIS FILE"
Exit Sub
Else
Word.Documents.Open (objFile.Path)
FindCitations
Set objDoc = Documents(Documents.Count - 1)
If objDoc Is Nothing Then 'counter keeps track of how the number of documents being processed
docCount = 0
Else
docCount = docCount + 1
End If
If Not objDoc Is Nothing Then 'saving the processed document with the prefix "NEW_"
objDoc.SaveAs (txtDestinationFolder.Text & "NEW_" & objFile.Name)
objDoc.Close
End If
If Documents.Count > 0 Then
Set objDoc = Documents(Documents.Count - 1)
If Not objDoc Is Nothing Then
objDoc.Close
End If
End If
End If
Else
MsgBox "No Word Documents exist in selected folder.", vbOKOnly, appName
Exit Sub
End If 'end check for documents ending with .doc extension
Else
MsgBox "No Documents exist in selected folder.", vbOKOnly, appName
End If
Next
End If 'end check to see if any files exist in the folder.
Else
MsgBox "Specified folder does not exist. Please choose a valid folder.", vbOKOnly, appName
txtDestinationFolder.SetFocus
Exit Sub
End If
MsgBox docCount & " Documents have been processed successfully!", vbOKOnly, appName
obviously, i cannot say end or exit sub here as this would take me out of the application.
help will be greatly appreciated. its quite urgent. thankssss