Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2016, 03:00 AM
ChrisJ83 ChrisJ83 is offline Repeat macro until no more fields Windows 7 64bit Repeat macro until no more fields Office 2013
Novice
Repeat macro until no more fields
 
Join Date: Nov 2015
Posts: 9
ChrisJ83 is on a distinguished road
Default Repeat macro until no more fields

Hi



I am trying to create a macro in Word which finds the next field, selects it and then changes the background colour to no fill.

I couldn't find a way of only selecting the field so it selects the whole line but that is fine, unless selecting the field on its own is easy enough?

My main question is how would I look the below code?

I have very limited knowledge of macros and I try and patch things together using the record function and references from the internet, so apologies for the state of the below code.

HTML Code:
Sub ASelect1()
'
' ASelect1 Macro
'
'
Selection.GoTo What:=wdGoToField, Name:="MergeField"
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Shading.Texture = wdTextureNone
Selection.Shading.ForegroundPatternColor = wdColorAutomatic
Selection.Shading.BackgroundPatternColor = wdColorAutomatic
End Sub
Any help/advice appreciated.

Cheers
Reply With Quote
  #2  
Old 01-20-2016, 04:13 AM
macropod's Avatar
macropod macropod is offline Repeat macro until no more fields Windows 7 64bit Repeat macro until no more fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 could use code like:
Code:
Sub ShadeFields()
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
  With Fld
    If .Type = wdFieldMergeField Then
      With .Result.Shading
        .Texture = wdTextureNone
        .ForegroundPatternColor = wdColorAutomatic
        .BackgroundPatternColor = wdColorAutomatic
      End With
    End If
  End With
Next
End Sub
but if the aim includes displaying/hiding field shading, you might need to adjust that via File|Options|Advanced>Show document content>Field shading. That too could be changed via code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-20-2016, 04:55 AM
ChrisJ83 ChrisJ83 is offline Repeat macro until no more fields Windows 7 64bit Repeat macro until no more fields Office 2013
Novice
Repeat macro until no more fields
 
Join Date: Nov 2015
Posts: 9
ChrisJ83 is on a distinguished road
Default

Hi macropod

That's brilliant that is exactly what I was after.

Thank you for taking the time to help out!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
Repeat formula 5 times and repeat? Jenny345 Excel 4 06-14-2013 04:37 PM
Repeat macro until no more fields Text will repeat in the fields ypurcaro Word 1 02-07-2013 01:46 AM
need macro for quiz (?) repeat of wrong answers with shuffle braveshark PowerPoint 0 10-02-2012 06:10 AM
Using fields to repeat data throughout a document Brasada Word 0 07-20-2010 02:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:45 AM.


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