Batch Update problems...

B

Bill Foley

Hey Gang,

A few weeks ago someone helped me with a batch update to change document
properties (Word 2003). I got a macro to change the "Title" and it worked
like a champ. I modified it to change the "Author" and it too worked like a
champ. I recently modified it to change the "Subject" and it goes through
the whole "Wend" but nothing got changed. See code below. Any ideas? this
is driving me crazy! TIA!

======Author code that works======

Sub BatchProcessAuthorChanges()
Dim strFileName As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" _
Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strAuthor = InputBox("Enter the new Author to be assigned to each
document.", "Batch Replace Authors")
strFileName = Dir$(strPath & "*.doc")
While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)
oDoc.BuiltInDocumentProperties(wdPropertyAuthor) = strAuthor
'Close the modified document after saving changes
oDoc.Close SaveChanges:=wdSaveChanges
strFileName = Dir$()
Wend
End Sub

====End of Author Change code====

======Subject Change code that DOES NOT work======

Sub BatchProcessSubjectChanges()
Dim strFileName As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" _
Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strSubject = InputBox("Enter the new Subject to be assigned to each
document.", "Batch Replace Subjects")
strFileName = Dir$(strPath & "*.doc")
While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)
oDoc.BuiltInDocumentProperties(wdPropertySubject) = strSubject
'Close the modified document after saving changes
oDoc.Close SaveChanges:=wdSaveChanges
strFileName = Dir$()
Wend
End Sub

====End of Subject Change code that DOES NOT ====

Bill Foley
 
D

Doug Robbins - Word MVP

I cannot see why it would not work, but try using

oDoc.Save
oDoc.Close

rather than relying on Word to make up its mind whether there are changes
that should be saved or not.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
B

Bill Foley

Just tried it on one folder of files - it worked!

Tried it on another folder of files - NOPE!

Go Figure!

Bill Foley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top