Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2021, 01:40 AM
StingerMKO StingerMKO is offline CustomDocumentProperties not shown in header / footer / textfield Windows 10 CustomDocumentProperties not shown in header / footer / textfield Office 2019
Novice
CustomDocumentProperties not shown in header / footer / textfield
 
Join Date: Apr 2021
Posts: 2
StingerMKO is on a distinguished road
Default CustomDocumentProperties not shown in header / footer / textfield

Hello,

I added some CustomDocumentProperties to my document which should be filled with a VBA form

When I open the form, fill out the fields and want to populate the entries to the custom fields in my document, only the ones which are in the text itself are added.
The fields which I added in header/footer or in textfields in the document are not filled.
This ist the code of the button click in the VBA Form:

Code:
Private Sub inpDocGenerate_Click()
 
 
 
 
    ' Update the properties values
    ActiveDocument.CustomDocumentProperties("customDocType").Value = Me.inpDocType.Value
    ActiveDocument.CustomDocumentProperties("customClientName").Value = Me.inpClientName.Value
    ActiveDocument.CustomDocumentProperties("customDocTitle").Value = Me.inpDocTitle.Value
    ActiveDocument.CustomDocumentProperties("customOfferNum").Value = Me.inpOfferNum.Value
    ActiveDocument.CustomDocumentProperties("customDate").Value = Me.inpDate.Value
    ActiveDocument.CustomDocumentProperties("customCity").Value = Me.inpCity.Value
    ActiveDocument.CustomDocumentProperties("customAspName").Value = Me.inpAspName.Value
     
 
 
    ' Show changes of document properties in document
    ActiveDocument.Fields.Update
 
    ' Hide the userform
    UserForm1.Hide
 
End Sub

Reply With Quote
  #2  
Old 04-22-2021, 04:19 AM
gmayor's Avatar
gmayor gmayor is offline CustomDocumentProperties not shown in header / footer / textfield Windows 10 CustomDocumentProperties not shown in header / footer / textfield Office 2019
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

Only the fields in the main story range are updated using your code. Instead of using
Code:
ActiveDocument.Fields.Update
call the following macro. This should work for most circumstances. If it doesn't work for your document you will need a more thorough processing of the various story ranges that make up the document.
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
lbl_Exit:
    Set oStory = Nothing
    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
  #3  
Old 04-22-2021, 04:52 AM
StingerMKO StingerMKO is offline CustomDocumentProperties not shown in header / footer / textfield Windows 10 CustomDocumentProperties not shown in header / footer / textfield Office 2019
Novice
CustomDocumentProperties not shown in header / footer / textfield
 
Join Date: Apr 2021
Posts: 2
StingerMKO is on a distinguished road
Thumbs up

Nice! This did the trick.
Thank you!
Reply With Quote
  #4  
Old 04-22-2021, 08:49 AM
Charles Kenyon Charles Kenyon is offline CustomDocumentProperties not shown in header / footer / textfield Windows 10 CustomDocumentProperties not shown in header / footer / textfield Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,128
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Nice! This did the trick.
Thank you!
Graham does not like to toot his own website, but you should know about it. He has this an a number of other great macros. A version of that macro can be found on his page: Instructions for Installing Macros from Forums or Websites by Graham Mayor, MVP

He also has at least three pages of example macros. One of them is: VBA Code Examples (3) by Graham Mayor, MVP. His main page is: Microsoft Word Tips by Graham Mayor, MVP

If you are going to be using vba, I recommend strongly that you become familiar with his site as well as the MVP page: Word Macros and Visual Basic for Applications (VBA) FAQ and Greg Maxey's site: Microsoft Word Help, Tips and Tutorials @ The Anchorage
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding text to the header and footer without removing all other content in the header and footer digitalelise Word VBA 2 10-23-2019 02:58 AM
Get CustomDocumentProperties vince692 Word VBA 8 05-13-2016 12:34 AM
Header and footer aligned in the footer area ashiqghfr Word 2 07-23-2015 01:14 AM
CustomDocumentProperties not shown in header / footer / textfield Document Variables vs CustomDocumentProperties Cosmo Word VBA 2 08-11-2014 01:35 PM
Set focus on a textfield on a repeating table happydigit Misc 0 11-24-2005 04:12 AM

Other Forums: Access Forums

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