Datepicker content control - extract value into another document using VBA in Word -
i have 2 word documents (doc1.docm) , (doc2.docm). in doc1.docm, select month , year (the format: mmmm yyyy), using date picker content control. defined date picker field "date1".
i trying automnatically update new content field in doc2.docm in header when select month , year in doc1.docm.
i can in same document using doc1.docm when using code:
private sub document_contentcontrolonexit(byval contentcontrol contentcontrol, cancel boolean) dim cctrl contentcontrol if contentcontrol.title = "date1" each cctrl in activedocument.contentcontrols if cctrl.title = "date2" cctrl .lockcontents = false .range.text = format(contentcontrol.range.text, "mmmm yyyy") .lockcontents = true end exit end if next end if end sub
does know how can update doc2.docm when select month , year in doc1.docx?
you have open other word document. can achieved programatically via:
dim worddoc object set worddoc = createobject("word.application") worddoc.documents.open("c:\doc2.docm")
you can manipulate contents of doc2.docm programatically, doing doc1.docm. if wondering why document doesn't show up: it's hidden. create visible have set worddoc.visible = true
. don't forget close doc2 1 time changes have been made via worddoc.quit
vba ms-word word-vba
No comments:
Post a Comment