First time post and whilst I may be trying to run before I can crawl, here is my situation (using Word 2013).
I have created a Userform where Branch A, asks for all of the data required to populate a document (fixed format and cannot be altered) used in our organisation, for a particular instance.
The document is now saved as a ".docx" file, stripped of the macros (vba
code). So far so good.Branch B, is intended to allow the loading of an existing document created in Branch A (as above). The data from this existing document should now be copied over to the Userform embedded in the new document created when double- clicking the template, to allow updating of various fields, whilst avoiding the necessity of re-input of unchanged details (to be subsequently saved as '.docx').
I am able to launch the new document by double-clicking the template and then via command button, execute the code to open the pre-existing document.
But this is where I start to get horribly confused...
When I begin by creating a new document through the template, Project Explorer looks like this...
Project Explorer on new document from template
Now I open an existing document (Filled.docx) in VBA to give a Project Explorer view like..
Existing doc opened in preparation for copying of data
So now I have 2 instances of ThisDocument
.
The code is being executed under '(DOC Generator)'
The data I want to extract/copy to the userform in (DOC Generator) is
ThisDocument
in (Filled).When I am finished editing the information in the userform, I will save
ThisDocument
(Document1) as I would, had I been creating an entirely new document.
The difficulty I have is, how do I reference an ActiveX control in the existing document to copy it to the userform.
Something like this???
txt_Author = ThisDocument.lbl_AssessingOfficer.Caption, where
- txt_Author is a textbox in the userform, and,
-ThisDocument.lbl_AssessingOfficer.Caption
is intended to refer to a label in the existing document (Filled) which holds the data.
Except that when I test this, ThisDocument
or ActiveDocument
both pick-up
the data from ThisDocument
(Document1).
How do I reference the label (data) from ThisDocument
under (Filled)?
Thankyou in advance for any help and your patience. If I could be so bold, if possible when answering, it would be extremely helpful to me (and maybe subsequent others) if you could explain how the code referencing works.