PDA

View Full Version : Create macro to run a boilerplate memo, pause for input and then continue running



dewachter
07-16-2016, 07:30 PM
A long time ago in Wordperfect, I was able to create macros that would run boilerplate text, pause for user input and upon using enter would continue with the rest of the boiler plate. The language is quite repetitive and I would like to create a macro or VBA in Word where the user would launch the macro from the menu and the macro would enter some lines of text into the document. It would then pause and prompts the user to insert their own variable text (with use of the InputBox). After entering the variable, the macro would continue running until the next variable needed to be entered and again stop for user input.

I am extremely new at VBA for Word but have some basic knowledge of macros.

I have several boilerplate memorandums that need to be generated where there are several variables that can be entered by the user. For example

I, (fill in first and last name), was scheduled to work at (fill in name of the business), located at (fill in the address) on (fill in the day of the week), (fill in the month) (fill in the date), (fill in the year) between (fill in start time in military time) and (fill in end time in military time). I completed the assignment and worked (enter number of hours worked) hours.

Thank you,

(enter first and last name)
(enter title/position)

Any input or suggestion would be helpful. Also if there is a simple reference work that I could access for research I would welcome the suggestion

Dirk

jec1
07-16-2016, 07:49 PM
Hi,

You really don't need a macro. You could use Content Controls to create a memo template. You could also use legacy fields.

I attach a very simple memo using Content Controls for Date and Picture. You can have author dropdowns and much more.

You should search Content Controls - there are some good articles on how to use them.

Just a suggestion.

Jen

gmayor
07-16-2016, 08:44 PM
As Jen suggests, this is ideally suited to content controls (display the Developer tab for the content control command set), or you could use VBA with a userform (http://www.gmayor.com/Userform.htm), or a combination of the two.

mdmackillop
07-17-2016, 12:42 AM
Jen
I'm having trouble opening your attachment. Word says "problem with contents". No additional details.

gmayor
07-17-2016, 04:53 AM
Rename it to remove the additional docx extension and it will open - not that it conveys much. The message itself is a more useful indicator.

jec1
07-17-2016, 05:28 AM
Thank you Graham.

If you Open Microsoft Word and press File>New> then type Memo in search box then a few of the examples have Content Controls.

As Graham knows Greg Maxey is the Content Control expert so to speak and I think Graham is also an expert in Content Controls.

Jen

dewachter
07-17-2016, 02:18 PM
Ok, so I created a template using a combination of content controls (date picker, plain text - so i can tab through the fields).

This is my first attempt at form creation in Word 2010 and I have a few follow-up questions:

1) How do I go about protecting the document so the user can only enter the data in the fields
2) How can i set up the form to force the user to save it under a different file name?
3) Can I create a UserForm from the content control template form?

Just from looking at the information found in the searches, I just sticking my big toe in a big pond of form creation. I do like to thank you for pointing in the right direction.

Dirk

jec1
07-17-2016, 03:34 PM
Hi Dirk

Yes it is.

Explanation Content Controls: http://gregmaxey.mvps.org/word_tip_pages/content_controls.html

Content Controls Tool (download) and place in Startup Folder (there are instructions): http://gregmaxey.mvps.org/word_tip_pages/content_control_tools.html

Dirk in a memo I assume you have something similar to below - a 2 column table with headings on left and input in right hand column
Date: Date CC
To: CC ComboBox so you can a name not in list (just a guess)
From: CC ComboBox (list of authors names)
Subject: Plain Text CC

End of 2 Column Table

Body CC (remove Content Control set)


What sort of company environment are you in Dirk?

1) http://gregmaxey.mvps.org/word_tip_pages/content_control_fillin_form.html
https://msdn.microsoft.com/en-us/library/bb386290.aspx

2) Use File New as the template form would be saved as a .dotx or .dotm. It depends on the environment. Are you a network?

3) Yes but you don't really need user forms for letter memo etc: http://gregmaxey.mvps.org/word_tip_pages/populate_userform_listbox_or_combobox.html

This should keep you very busy Dirk.

Jen

dewachter
07-17-2016, 04:25 PM
Jen, you've been a great help and I will look through those tools. I did save my form as a *.dotm file. I already played with the protection of the document and will explore options how to save it under another name. I saw somewhere that you could set the default name to something different than the assigned template name.

Also, I have several repetitive fields in the memorandum, like the first and last name of a person. Is there a way to only have to enter it once and then autofills the other needed entries.

I included what I have put together thus far.

See attached file.16644

Paul_Hossler
07-17-2016, 07:01 PM
One way would be to put a bookmark around the content control (say "OfficerName") and then use {REF} in the text (say {REF "OfficerName"} )

I've always found it a little sensitive to spaces, and getting the bookmark positioned just right

16645

Some of the Word-Masters might have easier ways

Rename the extension to get rid of the .zip part

gmayor
07-17-2016, 08:47 PM
It would be better to use content control mapping to repeat the values from controls - see http://gregmaxey.mvps.org/word_tip_pages/mapped_content_controls.html and the links there.

jec1
07-17-2016, 11:35 PM
Hi Dirk

Sorry for delay. Please do as Graham and I suggest download Greg Maxey's content control tools addin. A must have.

I attach a memo template, the cc_List variables to be loaded for Combo Content Controls - you use these as you can type info if what is in dropdown is not what you want.

The template memo.dotm (2 macros - auto insert today's date and delete CCs when finished and leave content - green button attached to template)

I saw your create date - but prefer not to mix legacy fields and CCs.

Once you install Content Control Tool you will be in mapping Content Control heaven. You can do quite a lot.

A short video demo: https://1drv.ms/v/s!ArGU6IkMJOsche1PsiKrmjldSpNiRw

You can restrict template but I don't think you should (smile).

I have used Content Control Mapping (video will show you what I mean) - it is well worth the time with Combo Dropdowns and cc_Lists to fill the Combo Dropdowns. You can then load the lists in Content Control Tool (Greg Maxey) and save the template.


Jen

Paul_Hossler
07-18-2016, 07:06 AM
It would be better to use content control mapping to repeat the values from controls - see http://gregmaxey.mvps.org/word_tip_pages/mapped_content_controls.html and the links there.


I had looked into the add-in (earlier version), but re-looked at ver 3 . More improved and user friendly

It was / is never obvious to me how to have the contents of a CC repeated in the text similar to the way a REF field will repeat a bookmark.

By experimenting, I found that if I manually copy a CC and then paste it into the text they'll both update in sync. Might be obvious, but to me it was a breakthrough :thumb

I was looking in the add-in for a "Insert a Linked CC" to put one at the insertion point. If there is, I could not find it ... sorry

jec1
07-18-2016, 03:10 PM
Hi Dirk

Please use this attached Memo template where the date macro is working.

Jen

dewachter
07-18-2016, 08:24 PM
So am I to understand that you can create these separate reference documents with the separate lists to be used and linked to in the combo boxes?

jec1
07-18-2016, 09:21 PM
Yes it is an option with the CC Tool. Benefit is it is easier to edit the list and reload into Templates and you can use in more than one template.

To duplicate a mapped CC you copy the first one and paste in the document template where you want it.

16665

gmaxey
07-19-2016, 08:02 PM
Paul,

I'll look at the content of the web page for that tool as soon as I get time and see I can do a better job of making your breakthrough more obvious. You aren't missing anything. The tool was conceived as a tool to map controls and was wrongly assuming users would know what to do with the controls once mapped.

However, if you design your form before mapping use like named controls for data you want repeated you can use the InstaMap feature and "Link like titled controls" to the same data node.

Paul_Hossler
07-21-2016, 01:34 PM
Paul,

I'll look at the content of the web page for that tool as soon as I get time and see I can do a better job of making your breakthrough more obvious. You aren't missing anything. The tool was conceived as a tool to map controls and was wrongly assuming users would know what to do with the controls once mapped.

However, if you design your form before mapping use like named controls for data you want repeated you can use the InstaMap feature and "Link like titled controls" to the same data node.


1. Thanks, you helped me out big time by explaining CustomXML awhile ago, so I sort of recognized some of the node structure, etc., but never connected the dots

http://www.vbaexpress.com/forum/showthread.php?55137-How-to-store-reference-data


2. If you get a chance to look at it, I was thinking a 'simple' mode: just a list of CCs by Name and a [Insert at Insertion Point] option. It seems like it's there by right-clicking a node on the node tree, but for us hacks, it's not very obvious. If I insert a CC and name it (e.g.) "Due_Date", that'd be the way I'd want to refer to it to insert it somewhere else


3. Small note: it seems the font on the user form and it's controls shows too large, at least on my machine (attachment)

gmaxey
07-21-2016, 08:48 PM
Paul,

I added some additional text in the User Notification Panel and in the tips page and fixed the split label. As far actual changes to the form/function I don't have time for all the follow on testing right now. You can down load the changed template from the site. Revision number unchanged.