Hi
I need to update several docs (currently 17) but this will be a regular occurrence in future. Obviously, it is pain to open each of them, update couple of fields, save & close them.
So the question is: is it possible to update several documents in a folder without manual intervention? The only thing I need to do the documents is update a custom properties field, a cell in a table, accept all changes and save.
Any help, highly appreciated.
Thanks.
Robie
Edit severals in a folder (without manual intervention)
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
-
- Administrator
- Posts: 78474
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Edit severals in a folder (without manual intervention)
Place the documents to be updated in a folder; this folder should not contain other Word documents.
You can then run a macro that opens each of the documents in turn, processes it, then saves and closes it:
You can then run a macro that opens each of the documents in turn, processes it, then saves and closes it:
Code: Select all
Sub UpdateDocs()
Dim strFolder As String
Dim strFile As String
Dim doc As Document
' Ask user to specify a folder
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strFolder = .SelectedItems(1)
Else
MsgBox "No folder selected.", vbExclamation
End If
End With
' Make sure that the path ends in a backslash \
If Not Right(strFolder, 1) = "\" Then
strFolder = strFolder & "\"
End If
' Loop through the .doc files in the folder
' Change to .docx if necessary
strFile = Dir(strFolder & "*.doc")
Do While Not strFile = ""
' Open document
Set doc = Documents.Open(strFolder & strFile)
' Process the document
' The following lines are just an example
' Modify as needed
doc.CustomDocumentProperties("MyName") = "Robie"
doc.AcceptAllRevisions
' Close and save the document
doc.Close SaveChanges:=True
' Next filename
strFile = Dir
Loop
End Sub
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Edit severals in a folder (without manual intervention)
Thank you very much Hans. That works perfectly. :0)
Didn't realise it could be this simple to process documents in a folder. It's easy when you know how :0). Thanks.
Didn't realise it could be this simple to process documents in a folder. It's easy when you know how :0). Thanks.