Hi,
I would like to update the comments field in the workbook properties of all the workbooks in a particular folder.
Ideally, I would like to add the following line to the Workbook_BeforePrint procedure:
How can I copy this line into the procedure?
Below is the code that I have so far....
Many thanks in advance
I would like to update the comments field in the workbook properties of all the workbooks in a particular folder.
Ideally, I would like to add the following line to the Workbook_BeforePrint procedure:
Code:
ActiveWorkbook.BuiltinDocumentProperties("Comments").Value = "Based on a template developed by mwperkins"
How can I copy this line into the procedure?
Below is the code that I have so far....
Code:
Option Explicit
Sub ApplyDocumentComments()
On Error Resume Next
Dim File_Name, Msg, Style, Title, Response
Dim fs, I
Dim oFSO As Object
Dim MainWorkbook As Workbook
Set fs = Application.FileSearch
Set MainWorkbook = ActiveWorkbook
Set oFSO = CreateObject("Scripting.FileSystemObject")
'activate the Search - START
With fs
.LookIn = Range("C2").Value
.Filename = "*.xls"
.SearchSubFolders = True
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
'If more than 200 files have been found provide a chance to quit - START
If .FoundFiles.Count > 200 Then
Msg = " " & .FoundFiles.Count & " files found matching your search critieria." & vbCr _
& vbCr & "This activity may take some time." & vbCr _
& vbCr & "Are you sure you want to continue?"
Style = vbYesNo + vbInformation + vbDefaultButton1
Title = "... it would be rude to say No..."
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then
Exit Sub
End If
End If
'If more than 200 files have been found provide a chance to quit - END
'Process each file - START
On Error Resume Next
For I = 1 To .FoundFiles.Count
'Set oFSO = CreateObject("Scripting.FileSystemObject")
Set File_Name = oFSO.GetFile(.FoundFiles(I))
Workbooks.Open File_Name
'Ideally, I would prefer to copy the following line into the "Workbook_BeforePrint" procedure:
ActiveWorkbook.BuiltinDocumentProperties("Comments").Value = "Based on a template developed by mwperkins"
ActiveWorkbook.Close True
MainWorkbook.Activate
Next I
On Error GoTo 0
'Process each file - END
Else
MsgBox "There were no files found."
End If
End With
Range("B2").Select
End Sub
Many thanks in advance