|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How do I programmatically insert and append the text from AutoText 0002 to the end of the existing t
Goal
I am trying to use VBA to programmatically insert and append the text from AutoText 0002 to the end of the existing text in the DraftingField below, if any. Catalog of AutoText statements: 0001 This text was inserted using 0001 and is paragraph 1 with cool Choose an item.. blah blah. 0002 This text was inserted using 0002 and should be paragraph 2 and appear directly below paragraph 1 in the drafting field, not write over the existing data in the field. Click here to enter a date.. blah blah and more Click here to enter text. Validation when successful: If the buttons work correctly as desired, after clicking “Insert 0001” the DraftingField should read: “This text was inserted using 0001 and is paragraph 1 with cool Choose an item.. blah blah.” Then, if I click “Insert 0002”, the DraftingField should add the text from AutoText 0002 to the end of the existing text in the field and the field should read: “This text was inserted using 0001 and is paragraph 1 with cool Choose an item.. blah blah. This text was inserted using 0002 and should be paragraph 2 and appear directly below paragraph 1 in the drafting field, not write over the existing data in the field. Click here to enter a date.. blah blah and more Click here to enter text.” · My current code is: Private Sub Insert0001_Click() Selection.GoTo What:=wdGoToBookmark, Name:="DraftingField" Application.Templates("C:\Users\erikm\Desktop\test .dotm").BuildingBlockEntries("0001").Insert Where:=Selection.Range, RichText:=True End Sub Private Sub Insert0002_Click() Selection.GoTo What:=wdGoToBookmark, Name:="DraftingField" Application.Templates("C:\Users\erikm\Desktop\test .dotm").BuildingBlockEntries("0002").Insert Where:=Selection.Range, RichText:=True End Sub I have the Word file created with AutoText 0001 and 0002 and the AutoText and their drop down menus, date picker, and enter text controls work perfectly. The buttons work, but when I click button 0001 and then click button 0002, the text from AutoText 0002 overwrites the existing text (text inserted from AutoText 0001) in my DraftingField. Instead, I want button 0002 to append its text to the end of any text already in the DraftingField. I have attached the file. Thanks! |
#2
|
||||
|
||||
Cross-posted at: https://social.msdn.microsoft.com/Fo...?forum=worddev
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Insert Existing Comments at the End of Comment Selection Text | mercadogs | Word VBA | 3 | 12-31-2015 03:49 AM |
Append to Existing file | charlesdh | Word VBA | 12 | 07-30-2015 08:21 PM |
How do i insert autotext using a contol toolbox checkbox | NP85 | Word VBA | 12 | 02-09-2014 03:06 PM |
Insert identifiers in AutoText snippet. Microsoft word | deepgreen | Word | 13 | 01-21-2014 05:16 PM |
Append text to a cell with color | gvdm | Excel | 1 | 04-17-2012 10:21 AM |