Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2018, 03:52 PM
Duddits Duddits is offline Update Fields within text box Windows 10 Update Fields within text box Office 2013
Novice
Update Fields within text box
 
Join Date: Sep 2018
Posts: 2
Duddits is on a distinguished road
Question Update Fields within text box

Hi,




I have a macro which sets some document variables within a document which is opened by this macro. This works fine for variables which are located outside of text boxes by using ActiveDocument.Fields.Update .

But it seems that this command does not effect variables within text boxes. In generated document I have to update the fields within text boxes manually by context menu. The Shape Object does not contain Fields property.


So: Do you have an idea how I can solve this problem?


Best regards
Duddits
Reply With Quote
  #2  
Old 09-15-2018, 07:53 PM
gmayor's Avatar
gmayor gmayor is offline Update Fields within text box Windows 10 Update Fields within text box Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Use instead the example code at http://www.gmayor.com/installing_macro.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 09-16-2018, 12:14 AM
Duddits Duddits is offline Update Fields within text box Windows 10 Update Fields within text box Office 2013
Novice
Update Fields within text box
 
Join Date: Sep 2018
Posts: 2
Duddits is on a distinguished road
Default

Hi,


thanks for your suggestion. But replacing ActiveDocument.Fields.Update by calling that sub has no effect: Again everything outside of the Textbox is updated but not fields within text box


Best Regards
Duddits
Reply With Quote
  #4  
Old 09-16-2018, 12:49 AM
macropod's Avatar
macropod macropod is offline Update Fields within text box Windows 7 64bit Update Fields within text box 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

Is there a reason you can't use single-cell tables (which you can apply text wrapping to) instead of text boxes? Fields in table cells will update without the convoluted process needed for fields in textboxes.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-16-2018, 01:24 AM
gmayor's Avatar
gmayor gmayor is offline Update Fields within text box Windows 10 Update Fields within text box Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The code from my web site should work in a text box ... and certainly does here. However it may not work if the text box is located in a header/footer in which case you need more brute force to update it e.g.


Code:
Sub UpdateAllFields()
Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        oStory.Fields.Update
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                oStory.Fields.Update
            Wend
        End If
    Next oStory
    UpdateFieldsAnotherWay
    Set oStory = Nothing
lbl_Exit:
    Exit Sub
End Sub

Sub UpdateFieldsAnotherWay()
Dim sView As String
Dim sUpdate As String
    sView = ActiveDocument.ActiveWindow.View.Type
    sUpdate = Options.UpdateFieldsAtPrint
    Options.UpdateFieldsAtPrint = True
    Application.ScreenUpdating = False
    PrintPreview = True
    PrintPreview = False
    ActiveDocument.ActiveWindow.View.Type = sView
    Options.UpdateFieldsAtPrint = sUpdate
    Application.ScreenUpdating = True
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Styleref Fields datech-hh Word VBA 18 11-04-2017 01:35 PM
Update Fields within text box How do I update all fields from a new input Kozzzle Word 7 10-19-2017 06:12 PM
Update Fields within text box macro to update fields PeaceDove Word 3 01-17-2012 02:45 PM
Macro to update fields rhatx Word VBA 0 03-02-2011 12:14 PM
VBA to update certain (but not all) fields sparkyrose Word VBA 0 05-20-2010 12:50 PM

Other Forums: Access Forums

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