PDA

View Full Version : [VBA Word] Drop down Menu and Content Repetition



legal86
11-17-2015, 12:03 PM
I work for a law firm and as part of my job, I draft a lot of trusts. Their average length is around 150-200 pages and they obviously differ a little bit from client to client. We’ve already got templates for the different types of trusts (joint, single, etc.) in place with content controls for the client’s name, address, trustees, etc etc. on the first couple pages, so that helps reduce repetitive typing and drafting time by quite a bit. But one area that is kind of slow involves the copying and pasting of specific paragraphs of text that may be needed depending on what the client wants. So for example, some clients want to allow gifting from their trust to only their spouse, in that case I’d go to my auto-text file, copy the specific paragraph I need, and then paste it in 4 different locations in the trust document. (While I'm drafting I always have two MS Word windows open, one with the clients trust and another with all of my auto-text that never changes.) Other clients might only allow gifting to third parties, so again, I’d go to my auto text file, copy that specific paragraph, and paste it in the appropriate locations.

To speed up the process, what I’d like to do is incorporate a small database of my legal text and use drop down menus in the first page of the template that allow me to select the type of text I need and then have that selection apply it to the multiple areas in the document where it’s supposed to go, this way I don’t have to have another MS Word window open. Is this something that’s possible? I’m assuming I’d have to learn some VBA programming to make this work, right? Any suggestions would be appreciated!

gmayor
11-18-2015, 06:54 AM
Cross posted at http://www.msofficeforums.com/word-vba/28767-drop-down-menu-content-repetition.html

MacroWizard
11-30-2015, 08:31 PM
On top of Auto Text, if you would like button selection, you can create a few sets of macros and place them on the Ribbon. A macro example for this would be:



Sub oTrusts()
'
Dim oDoc as ActiveDocument
'
Select Case Control.ID
'Inserts selection of trust type 1 or trust type 2 after the mouse cursor.
'
Case Btn1
oDoc.BuildingBlockTypes(wdTypeAutoText).Categories("Legal").BuildingBlocks("Trust1").Insert Selection.Range
'
Case Btn2
oDoc.BuildingBlockTypes(wdTypeAutoText).Categories("Legal").BuildingBlocks("Trust2").Insert Selection.Range
'
Case Else
'Do nothing
End Sub


Now, the trick is to add the drop-down using Custom UI Editor. With some simple XML, you can create a new tab on the ribbon that can contain several groups and buttons/dropdown menus.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="RibbonControl.Onload">
<ribbon>
<tabs>
<tab id="CustomTab1" label="LEGAL AID">
<group id="CustGrp1" label="GROUP 1" >
<gallery id="Gallery1" size="large" imagemso="">
<button id="Btn1" label="Trust Wife" size="large" image="LegalStyle1" onAction="RibbonControl.MyBtnMacro" />
<button id="Btn1" label="Trust No One" size="large" image="LegalStyle2" onAction="RibbonControl.MyBtnMacro" />
</group>
</tab>
</tabs>
</ribbon>

You can import images for the buttons using the Custom UI Editor. With a bit of research you should have it down in no time. Feel free to ask more questions here if you have any.

Edit: Also, there is code to add a quick part to a specific gallery and category. :)


Sub CreateLegalQuickPart()Dim oRng As Word.Range
Dim oTmp As Template
Dim oQP as String


'Prompts for a name for the Quick Part
Set oQP = InputBox("Name of Quick Part:", "Prompt!")


'Place the name of your template within the quotes
sPath = Options.DefaultFilePath(wdUserTemplatesPath) & "LegalTemplate.dotm"
Set oTmp = Templates(sPath)
oTmp.BuildingBlockEntries.Add _
Name:=oQP, Type:=wdTypeQuickParts, Category:="Legal", _
Range:=oRng, InsertOptions:=wdInsertContent
lbl_Exit:
Exit Sub
End Sub

gmaxey
12-01-2015, 02:21 PM
MW

This is not going to work:

Sub oTrusts()
Dim oDoc As ActiveDocument
Select Case Control.ID

You have not passed the control parameter, and oTrusts is not the OnAction procedure in your XML, and you have not set the oDoc object variable.

Sub MyBtnMacro(Control As IRibbonControl)
Dim oDoc as Document
Set oDoc = ActiveDocument
Select Case ...

Also, and I am guilty of not always practicing what I might preach, RibbonControl is not really a good module name as it could easily be contained in multiple projects. Something unique to the project is better e.g., TrustProjRibCon

MacroWizard
12-02-2015, 05:36 PM
GM,

Thanks for the fine-tuning. It might have done me well to produce the document, versus just writing on the forum. :) As usual, you're spot on.