Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2024, 07:09 AM
Kriger1102 Kriger1102 is offline Auto Insert Template Windows 10 Auto Insert Template Office 2013
Novice
Auto Insert Template
 
Join Date: Feb 2024
Posts: 3
Kriger1102 is on a distinguished road
Default Auto Insert Template

I have created a Legacy Dropdown that has options of severity level. I wish to insert a table template named NSIR detail based of the Impact level of minor, moderate or severe level. I have attached the document along with this question. I am not sure why when I run the macro on exit, nothing happens. I have a total of 0.5 hr. of VBA experience, just very rudimentary xD
Attached Files
File Type: docx TEST.docx (21.4 KB, 2 views)
Reply With Quote
  #2  
Old 02-05-2024, 07:27 AM
Italophile Italophile is offline Auto Insert Template Windows 11 Auto Insert Template Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

As the document you have attached has the extension docx it clearly doesn't contain any VBA code.

Depending on where you want to insert your "table template" you may find it better to use a Building Block Gallery Content Control as this will allow the insertion of whatever text etc you want without the use of any code. You will need to use a document template (dotx) for this, not a document.
Reply With Quote
  #3  
Old 02-05-2024, 11:27 AM
Kriger1102 Kriger1102 is offline Auto Insert Template Windows 10 Auto Insert Template Office 2013
Novice
Auto Insert Template
 
Join Date: Feb 2024
Posts: 3
Kriger1102 is on a distinguished road
Default Modified based on suggesoitn

I have saved the document as a Macro Word, the Drop down lost under impact category is set to ran macro "NSIR" on exit. I kinda recorded a macro of inserting a building block and modified the VBA to insert the table as a building block instead based on the suggestion?? Nothing appears to be happening.

Sub NSIR()
Select Case ActiveDocument.FormFields("ddImpact").Result

Case "Minor Harm"
Selection.Range.ContentControls.Add (wdContentControlBuildingBlockGallery)
Selection.ParentContentControl.BuildingBlockType = wdTypeTables
Application.Templates( _
"C:\Users\wuz1\AppData\Roaming\Microsoft\Docum ent Building Blocks\1033\15\Building Blocks.dotx" _
).BuildingBlockEntries("NSIRDetail").Insert Where:=Selection.Range, _
RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Case "Moderate Harm"
Selection.Range.ContentControls.Add (wdContentControlBuildingBlockGallery)
Selection.ParentContentControl.BuildingBlockType = wdTypeTables
Application.Templates( _
"C:\Users\wuz1\AppData\Roaming\Microsoft\Docum ent Building Blocks\1033\15\Building Blocks.dotx" _
).BuildingBlockEntries("NSIRDetail").Insert Where:=Selection.Range, _
RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1

Case "Severe Harm"
Selection.Range.ContentControls.Add (wdContentControlBuildingBlockGallery)
Selection.ParentContentControl.BuildingBlockType = wdTypeTables
Application.Templates( _
"C:\Users\wuz1\AppData\Roaming\Microsoft\Docum ent Building Blocks\1033\15\Building Blocks.dotx" _
).BuildingBlockEntries("NSIRDetail").Insert Where:=Selection.Range, _
RichText:=True
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1

End Select
End Sub

This is my code for it. Nothing is happening.
Attached Files
File Type: docm TEST.docm (28.8 KB, 2 views)
Reply With Quote
  #4  
Old 02-05-2024, 11:36 AM
Italophile Italophile is offline Auto Insert Template Windows 11 Auto Insert Template Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Are you the only person that will use this? If not, you will need to save the document as a template and store the building blocks in that template.
Have you used Legacy Controls before? They only work if the document is protected for filling forms. Using a combo box content control would be a better option.
Reply With Quote
  #5  
Old 02-05-2024, 11:37 AM
Kriger1102 Kriger1102 is offline Auto Insert Template Windows 10 Auto Insert Template Office 2013
Novice
Auto Insert Template
 
Join Date: Feb 2024
Posts: 3
Kriger1102 is on a distinguished road
Default

This document will be saved as a word document template to share.
Reply With Quote
  #6  
Old 02-06-2024, 07:23 AM
gmayor's Avatar
gmayor gmayor is offline Auto Insert Template Windows 10 Auto Insert Template Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Without knowing what is in the building blocks it is difficult to advise, but you should not be using legacy form fields which require the form to be locked and content controls which don't. You should change the form field for a content control - see attached and also Insert Content Control Add-In

Then you run the code on exit from the content control, which in the example inserts one of three autotext entries saved in the template according to the selection. Make your selection and click outside the control. Note you have five selections in your list but only three options in your code.

Create a new document from the template. The building blocks in the example insert a table with text at the end of the document or change that table if one of the three options is selected (or remove it if one of the others is selected).

This should point the way.
Attached Files
File Type: zip TEST.zip (35.7 KB, 3 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 02-09-2024, 03:13 PM
Charles Kenyon Charles Kenyon is offline Auto Insert Template Windows 11 Auto Insert Template Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

See also:
That creates a dropdown of selected building blocks.


You may also want to save as a Quick Table.


These are both non-macro methods.
See also: Using VBA to Insent an AutoText Entry or other Building Block
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Insert Text from external sources jtm4890 Word 2 10-25-2022 06:54 PM
Auto insert table line johngav Word Tables 3 07-13-2017 08:44 AM
Auto Insert Template Auto insert year only fithawk Word 11 12-21-2016 02:50 AM
Auto Insert Template auto insert names from list for printing andreipopa2k Word 1 12-09-2011 01:51 PM
Form auto insert DaveC Word 4 06-20-2010 04:14 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:53 PM.


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