![]() |
|
![]() |
|
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!!! ![]() |
#2
|
||||
|
||||
![]()
You probably don't want to delete all fields, especially those in headers & footers. For example, if the document contains page numbering in the header/footer, every page will likely end up numbered '1' as a result. Likewise, a Table of Contents would cease to work as would hyperlinks to web pages, etc. Furthermore, unlinking all fields makes future document maintenance far more difficult.
If you want to 'harden' a document for distribution, simply save it as a PDF and distribute that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thank you, but that's exactly what I need. To "harden" the Word file.
I need to distribute Word files as other people down the line need to edit them, but I don't want to give them all my macros, because then they will start to use them by themself and mess up everything. Is is THAT hard to mimic CTRL(CMD)+6 in all sections? You're right about page numberings, I hadn't thought about that. Thank you. |
#4
|
||||
|
||||
![]()
Removing fields in a document has no effect on any macros it contains. Although macros and fields can interact, the two are entirely different and serve different purposes. If you want to distribute a document for editing without macros, simply save it in the .docx format before distribution.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
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 |