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
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