![]() |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
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 Code:
Sub BookmarkKiller() Application.ScreenUpdating = False With ActiveDocument While .Bookmarks.Count > 0 .Bookmarks(1).Delete Wend End With Application.ScreenUpdating = True End Sub 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!!! ![]() |
Tags |
fields, remove, remove fields |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
JT Helstrom | Word | 4 | 09-29-2018 03:13 PM |
Set of footers/headers per document | linneasee | Word | 3 | 06-07-2018 05:20 AM |
Adding Headers and Footers to a Document | babysatch | Word VBA | 3 | 05-02-2017 10:08 AM |
![]() |
Jim-ski | Word | 7 | 12-07-2015 09:30 PM |
![]() |
ghphoto | Word | 2 | 02-22-2015 05:49 PM |