Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2016, 06:58 AM
JonFleming JonFleming is offline Updating a custom property in the header Windows 10 Updating a custom property in the header Office 2016
Novice
Updating a custom property in the header
 
Join Date: Feb 2016
Posts: 15
JonFleming is on a distinguished road
Default Updating a custom property in the header

I'm working on a macro for a document to submit to the FDA. There's a bunch of items that appear many many times in the document and change when you start a new document. There's also a bunch of technical reasons why plain search and replace doesn't work and takes along time to fail.

So I've defined a custom property for each of these items. There's a table at the beginning of the document with the property names in the first column. The user fills in the second column with the desired value. My macro extracts the information from the table and changes the property value, turns off screen updating, then updates all instances of the property:



Code:
Sub UpdateSpecificPropertyFields(FieldName As String)
    Dim pRange As Word.Range
    Dim oFld As Word.Field
    For Each pRange In ActiveDocument.StoryRanges
        Do
            For Each oFld In pRange.Fields
                Select Case oFld.Type
                    Case wdFieldDocProperty
                        If InStr(oFld.Code.Text, FieldName) Then
                            oFld.Update
                        End If
                    Case Else
                       'Do nothing
                End Select
            Next
            Set pRange = pRange.NextStoryRange
        Loop Until pRange Is Nothing
    Next
End Sub
But the instances of the property in the header do not get updated. Help?
Reply With Quote
  #2  
Old 02-03-2016, 02:30 PM
macropod's Avatar
macropod macropod is offline Updating a custom property in the header Windows 7 64bit Updating a custom property in the header 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

How about:
Code:
Sub UpdateFields()
Application.ScreenUpdating = False
With ActiveDocument
  .Fields.Update
  .PrintPreview
  .ClosePrintPreview
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-04-2016, 08:16 AM
JonFleming JonFleming is offline Updating a custom property in the header Windows 10 Updating a custom property in the header Office 2016
Novice
Updating a custom property in the header
 
Join Date: Feb 2016
Posts: 15
JonFleming is on a distinguished road
Default

Much more clever than mine. But.
  • I only run that code once, the screen flashes obnoxiously once for each property (even though I'm only changing one) (yes, I did turn off screen updating).
  • The instance of the property in the header is not affected at all.
Reply With Quote
  #4  
Old 02-04-2016, 09:06 AM
JonFleming JonFleming is offline Updating a custom property in the header Windows 10 Updating a custom property in the header Office 2016
Novice
Updating a custom property in the header
 
Join Date: Feb 2016
Posts: 15
JonFleming is on a distinguished road
Default

Whoopsie, cancel......

My code is updating the headers, with almost no flickering (just the cursor). It's a long story of several errors why I thought it wasn't.
Reply With Quote
  #5  
Old 02-04-2016, 03:20 PM
macropod's Avatar
macropod macropod is offline Updating a custom property in the header Windows 7 64bit Updating a custom property in the header 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

So, is the problem solved? Your posts are ambiguous. You refer to your code & flickering, but there should be no flickering with the code I posted. As for the "long story of several errors", you originally mentioned results such as "Error! Unknown document property name.", but those have nothing to do with the code I posted and instead reflect erroneous field constructions in your document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 02-05-2016, 06:03 AM
JonFleming JonFleming is offline Updating a custom property in the header Windows 10 Updating a custom property in the header Office 2016
Novice
Updating a custom property in the header
 
Join Date: Feb 2016
Posts: 15
JonFleming is on a distinguished road
Default

The problem is solved. I don't exactly know why it's fixed. but the fields in the headers are now updating.

Running the code you posted, the pane on the left (search results) and the pane at the top (ribbon and tabs) turned white, and the screen flickered quite obnoxiously for several seconds. About six of the properly constructed field insertions turned into errors. (I inserted all fields via the GUI, if they are improperly constructed it's Word). I'm sorry, but that's what your code did.

(Word 2016/Office 365/Windows 10 Pro x64)
Reply With Quote
  #7  
Old 02-05-2016, 01:01 PM
macropod's Avatar
macropod macropod is offline Updating a custom property in the header Windows 7 64bit Updating a custom property in the header 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

There is nothing in the macro I posted that is capable of producing the behaviour you say you saw. It would appear that either your document is corrupt or you have a faulty Office installation; your document's erratic behaviour with your own code would seem to confirm that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 02-08-2016, 09:03 AM
JonFleming JonFleming is offline Updating a custom property in the header Windows 10 Updating a custom property in the header Office 2016
Novice
Updating a custom property in the header
 
Join Date: Feb 2016
Posts: 15
JonFleming is on a distinguished road
Default

Well, now my code is not working ,and yours is. Guess I'll have to put up with the screen flashing.

(see https://mega.nz/#F!H9IhSAIR!GERFff7xr5nwxL_gIu59Kg for proof).
Reply With Quote
  #9  
Old 02-08-2016, 02:12 PM
macropod's Avatar
macropod macropod is offline Updating a custom property in the header Windows 7 64bit Updating a custom property in the header 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

As indicated in my previous reply, it appears that either your document has acquired some for of corruption or you have a faulty Office installation.

Corrupt documents can often be 'repaired' by inserting a new, empty, paragraph at the very end, copying everything except that new paragraph to a new document based on the same template (headers & footers may need to be copied separately), closing the old document and saving the new one over it.

You could try repairing the Office installation (via Start > Windows Control Panel > Programs > Programs & Features > Microsoft Office (version) > Change > Repair).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 02-09-2016, 05:22 AM
JonFleming JonFleming is offline Updating a custom property in the header Windows 10 Updating a custom property in the header Office 2016
Novice
Updating a custom property in the header
 
Join Date: Feb 2016
Posts: 15
JonFleming is on a distinguished road
Default

The document is not corrupt. The installation of Office 365 is not corrupt.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a custom property in the header Update Custom Document Property in Template Byron Polk Word VBA 10 08-19-2014 07:19 AM
Updating a custom property in the header Insert image based on document custom property anandyrh Word 1 08-14-2013 12:08 AM
Custom Document Property Lost From Template bhaughey Word 8 03-05-2013 02:11 PM
Link Watermark to custom property kerend Word 0 04-08-2012 05:03 AM
Updating a custom property in the header QuickParts - custom document property untttt Word 2 06-09-2011 05:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:52 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