Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 

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 09:30 AM.


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