Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-11-2025, 03:23 PM
PDanes PDanes is offline Run code in remotely created Word doc Windows 10 Run code in remotely created Word doc Office 2021
Novice
Run code in remotely created Word doc
 
Join Date: Dec 2020
Posts: 12
PDanes is on a distinguished road
Default Run code in remotely created Word doc

I have documents created from a Word template. The template has some bookmarks and formfields, with OnExit calls to a macro. The original machinery was an Excel spreadsheet programmed to create new documents from this template, activated by clicking certain cells in the spreadsheet, then populate the fields from info in the spreadsheet. Recently, the customer decided he wanted QR codes added to the created documents. I've got that done, but it is important that the QR code reflects the contents of the document at all times. Mostly not a problem, OnExit calls attached to each field that the user is allowed to manually update after document creation takes care of that.



But there is one fly in the soup. When the document is first created, I need to update the QR code AFTER Excel finishes filling in the fields, and I haven't been able to figure out how to do that. I put things in the Document Open event, but that gets called as soon as the document is created, BEFORE the fields are filled in, so a QR code generated at that point reflects the then-blank status of the fields. Once the document is finished, any manual change in any field triggers generation of a new QR code, via the OnExit calls, so from then on, it is always current and accurate. But this in-between period is a problem – if the user does not make any further changes after the document is created, the QR code is never 'brought current', and if printed or emailed that way, will be seriously incorrect. And this is usually the case – most of the necessary info is in the spreadsheet, so subsequent manual editing will be the exception rather than the rule.

The only way I have found to make this correct is to add a call in the Excel VBA code to a public routine in the Word template, forcing the QR code generation 'from a distance', so to speak. However, I don't really like that. The spreadsheet is at the customer's place, full of his data, and delivering new code into that is a bit of a pain. I would like to simply send the customer blank new Word templates that will generate QR codes. And they do, except for this.

Is there any way to force Word to run this code AFTER Excel finishes filling in the bookmarked fields? The OnExit code runs when the fields are manually updated, but not when they are updated remotely from code. I haven't found anything that looks like an event I can have automatically fire when fields are updated remotely. I thought about a timer, but that seems a little too shaky – very easy to make the interval too long or too short, and have the results be incorrect again. There doesn't seem to be anything like 'Finished creating' event, or maybe something that would recognize when Excel 'releases' the newly formed document.
Reply With Quote
  #2  
Old 12-11-2025, 11:07 PM
Guessed's Avatar
Guessed Guessed is offline Run code in remotely created Word doc Windows 10 Run code in remotely created Word doc Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,187
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There are other document events that you could use.
Presumably the document gets saved - there is an event for DocumentBeforeSave for instance
Or DocumentBeforePrint

If you are putting the Excel content into Content Controls you could also use Document_ContentControlBeforeContentUpdate
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 12-12-2025, 12:23 AM
PDanes PDanes is offline Run code in remotely created Word doc Windows 10 Run code in remotely created Word doc Office 2021
Novice
Run code in remotely created Word doc
 
Join Date: Dec 2020
Posts: 12
PDanes is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
There are other document events that you could use.
Presumably the document gets saved - there is an event for DocumentBeforeSave for instance
Or DocumentBeforePrint

If you are putting the Excel content into Content Controls you could also use Document_ContentControlBeforeContentUpdate
I've looked at other document events, and none seemed to fit my situation. The BeforeClose or BeforePrint might work, but the doc would be in an incorrect state until that happened. I don't want that - the user might screen-shot the doc, or use his phone to snap an image and send that off. I want the doc to be correct always, or as always as possible. Sure the user could make a snap after changing text in a field, but before leaving the field, but I can't babysit every possible situation.

However, Content Controls sound promising. I've never worked with them - most my intensive programming with Word was years ago, but I'll have a look. Thank you for the idea.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
REf Fields show Bookmark whole cell when Bookmark is created by code. pmcpowell Word VBA 2 11-16-2019 07:05 PM
Run code in remotely created Word doc Dimensions of a Table Created in Word 2013 Change when saved in Word 2016 PKW57 Word Tables 2 05-26-2016 05:15 AM
Help: Using Mac remotely from PC based office (Google Docs) sijdavies OneNote 0 05-22-2016 03:10 PM
Run code in remotely created Word doc Linking to remotely stored PDF opens behind joeldodenhoff PowerPoint 1 08-22-2012 12:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft