Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2018, 06:07 AM
elocution elocution is offline How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Mac OS X How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Office 2016 for Mac
Novice
How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...)
 
Join Date: Dec 2018
Posts: 2
elocution is on a distinguished road
Default How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...)

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!!!


Reply With Quote
  #2  
Old 12-08-2018, 09:25 PM
macropod's Avatar
macropod macropod is offline How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Windows 7 64bit How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 12-11-2018, 06:15 AM
elocution elocution is offline How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Mac OS X How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Office 2016 for Mac
Novice
How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...)
 
Join Date: Dec 2018
Posts: 2
elocution is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 12-11-2018, 02:42 PM
macropod's Avatar
macropod macropod is offline How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Windows 7 64bit How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Tags
fields, remove, remove fields



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Can I copy the Headers and Footers from one document to another? 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
How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) Headers/Footers not in new document Jim-ski Word 7 12-07-2015 09:30 PM
How to mimic CTRL (CMD) + 6 (remove fields) in all sections of a document (headers, footers...) remove headers and footers ghphoto Word 2 02-22-2015 05:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft