![]() |
|
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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] |
#3
|
|||
|
|||
![]()
Much more clever than mine. But.
|
#4
|
|||
|
|||
![]()
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. |
#5
|
||||
|
||||
![]()
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] |
#6
|
|||
|
|||
![]()
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) |
#7
|
||||
|
||||
![]()
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] |
#8
|
|||
|
|||
![]()
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). |
#9
|
||||
|
||||
![]()
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] |
#10
|
|||
|
|||
![]()
The document is not corrupt. The installation of Office 365 is not corrupt.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Byron Polk | Word VBA | 10 | 08-19-2014 07:19 AM |
![]() |
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 |
![]() |
untttt | Word | 2 | 06-09-2011 05:24 PM |