Hi, I'm new to the forum. I have searched but I haven't found the answer to this. I apologize in advance if I didn't find something that was already here.
So, my problem is this: I have many word documents with INCLUDETEXT fields that pull data from a single file through bookmarks. Everything works very well, but I'd like to automate as much as possible the process of cleaning up the Word files before distributing them. I want to remove all fields and bookmarks and keep just the plain values.
I know almost nothing of VBA programming even if I program in other languages.
For the moment, I'm using these macros found online.
The first one updates all fields:
Code:
Public Sub UpdateAllFields()
Dim rngStory As Word.Range
Dim lngJunk As Long
Dim oShp As Shape
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stcories
Do
On Error Resume Next
rngStory.Fields.Update
Select Case rngStory.StoryType
Case 6, 7, 8, 9, 10, 11
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.TextFrame.HasText Then
oShp.TextFrame.TextRange.Fields.Update
End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub
While the second one deletes all the bookmarks left in the document:
Code:
Sub BookmarkKiller()
Application.ScreenUpdating = False
With ActiveDocument
While .Bookmarks.Count > 0
.Bookmarks(1).Delete
Wend
End With
Application.ScreenUpdating = True
End Sub
What I'm left with at this point is all the updated fields without the bookmarks.
Manually, I now select all (CMD+A) (I'm on a Mac) and remove the fields (CMD+6) for the main section, then the header, then the footer.
As I have really a lot of files this is very boring and I'd love to automate this process but still I haven't find a macro that works.
The last step would be to automate all the process on many files at the same time, but I guess this is a different and more general question.
Thank you very much for any help!!!