|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Want to use the DateAdd function to type text at a location in word document, using date from CC
I am trying to get a macro (VBA) to type the date in 6 or 12 months time.
I have managed to get it to work from today's date but that is unfortunately not the date that we need. We need it to add 6 or 12 months onto a date which is specified by the user in a DatePicker Content Control. The way this will be done is the user will either click "6th Months" or "12 Months" (MacroButtons) and this will run the corresponding macro (6 months will add 6 months onto the date specified). I then also need the macro to delete the other MacroButton, so that only the clicked button remains. I really need this urgently, and any help that anyone can provide will be greatly appreciated. Please disregard all VBA code within this doc, as the majority no longer works due to me keep having to change various parts. Please someone help me!!! Thankyou. [I'm only 15 and I'm really really new to this!] |
#2
|
||||
|
||||
There is no code in your documents as docx format does not support code.
You can use the content control exit event to perform calculations, something like the attached, but you need to name at least the relevant fields (and better still all of them) and you need to have a date value that you can add to. Your Date of Manufacture field shows only the year. You cannot add months to a year. So in the attached I have added a last examination field for the purpose of demonstration. The code adds six months of a year to the value of that date (or nothing if the field is showing the prompt).
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Genius!
Quote:
I have no idea how you managed to do this, and I am very grateful. Could you just do me one more huge favour please? Where you added the "Last Examination" line into the document, in order for it to calculate the "Next Examination" value, it actually needs to come from the date field which is in the black textbox at the bottom of the page. I have included an image with this reply so that it makes more sense. If you could look into this for me please, I would be most grateful - I am going to try to work it out by myself in the meantime, but I fear that I will be just as useless this time as the first time! Thankyou in advance, and for what you have done already. Callum |
#4
|
||||
|
||||
Just delete the paragraph that you have scribbled out. The other field already has the required name and that will be used by the macro.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
I'll try it now, and will update you accordingly!
|
#6
|
|||
|
|||
Quote:
There is only one issue with the document - since the user is more likely to enter the "LastExamination" text after they have entered the "Frequency" text how would I go about modifying the code to calculate the date after the "LastExamination" field is entered, rather than after the "Frequency" field. An even better solution would be to have it calculate/modify the "NextExamination" date after the "Freqency" or the "LastExamination" field is entered. Basically, that would mean that the "NextExamination" field would be populated correctly regardless of which order the user fills in the document; because at the moment, if the "Frequency" field is filled in before the "LastExamination" field (which is now at the bottom) the document displays a VBA error [Type Mismatch] - I can forsee this being an issue since trying to explain to the users that they need to fill in the bottom before the top will blow their minds! Any help that you could provide would be greatly appreciated; I did try to work it out myself, but the code is far too complex for me - my status on this site describes me perfectly - "Novice"! Kind Regards, Callum |
#7
|
||||
|
||||
This is becoming a major exercise
You can process any field on exit or on entry by use of event macros. I noticed that you used a date field - don't as this updates each time the document is opened, rendering it useless. You have also used a field for the examiner. This doesn't provide any facility to change the examiner. Use either a text content control or a dropdown control listing all the examiners. The form should be a template from which you create new documents - attached.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#8
|
|||
|
|||
Quote:
Thanks for that, is there any chance you could send me the non-template version please, as I need to add the company's logo and information back to it, and when I add it to your template, and then save that as a new template, the coding is lost! Kind Regards, Callum |
#9
|
||||
|
||||
Copy the company logo to the template then simply save the template (or don't forget to save as a macro enabled template) then the code should be retained.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#10
|
|||
|
|||
Quote:
I am downloading your most recent file, adding the logo, then saving said file as a MacroEnabled Template... |
#11
|
||||
|
||||
Send me the modified template to supportATgmayor.com (change AT to @) with your forum username in the message subject so I can see what you have (or have not) done.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to have the location (path) of the Word document on the title bar? | Jamal NUMAN | Word | 24 | 09-06-2017 12:18 PM |
Returning text, date, time, location from one Excel sheet to another | dave57 | Excel | 17 | 06-15-2017 10:45 AM |
Word type document auto fill in | Sircooks | Excel | 5 | 05-14-2016 05:01 AM |
Why do pages 10-24 disappear when I type in more text on page 2 or paste new text into the document? | RET | Word | 1 | 05-02-2016 07:28 PM |
Date Function in word? | aligahk06 | Word | 1 | 04-21-2010 06:33 AM |