|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks
Hello to all,
and happy new year! I was hoping some of the kind experts may be able to help me on this Autotext Building block problem. I have a number of building blocks that need to be inserted into documents. As per usual I have been running them individually. The Problem is I have too many building blocks to insert. For Example Find Code | Insert Building Block BBS1 | Signature 1 BBS2 | Signature 2 ............ ............ ............ and on and on etc Each document may have 10+ building blocks to find and insert. Hence what is a not once a difficult task becomes a rather manually laborious process - I have to do this to 100s of documents. I have seen this excellent thread. https://www.msofficeforums.com/word-...using-vba.html I have been trying to adapt it for the past week, and am just no closer to understanding the complex nature of the programming. My non working attempt Code:
Sub BuildingBlockArrayMacro() ' Replace Array Words with a Building Block - Autotext Dim Rng As Word.Range Dim ArrayList Dim i As Long ArrayList= Array("#BB1", "#BB2") For i = 0 To UBound(ArrayList) Set Rng = ActiveDocument.Range With Rng.Find .ClearFormatting .Text = ArrayList(i) .MatchWholeWord = True While .Execute ' Need to insert search? ' Got stuck here if .text = #BB1 then ActiveDocument.AttachedTemplate.Builtinbuildingblocks("Signature1").Insert Where:=Rng, RichText:=True ElseIf .text = #BB2 then ActiveDocument.AttachedTemplate.Builtinbuildingblocks("Signature2").Insert Where:=Rng, RichText:=True End With Next End Sub https://www.msofficeforums.com/word-...using-vba.html http://gregmaxey.com/word_tip_pages/...d_replace.html I do believe I am not structurally creating the code correctly - I've got VBA blindness again. To Recap I would like to: 1. Find specific text in my document 2. Replace each text with the correct building blocks I would be really grateful as always for helping to solve this problem. I appreciate this may be a very advanced VBA code - as to why I am really stuck and appreciate the time and help from the individuals on the forum. Thank you in advance for all your time and help. J |
Tags |
building block, vba word |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem batch adding autotext using Greg Maxey's Building Blocks Add-In | Genuine Gin | Word VBA | 5 | 12-16-2015 10:20 AM |
Formatting Issues When Using If Statements and Inserting Building Blocks/Autotext | sanko787 | Mail Merge | 1 | 07-05-2014 09:00 PM |
Building blocks show correctly in dropdown, but wrong building block populates in doc | wordgirl123 | Word | 0 | 10-03-2013 08:30 AM |
INSERT building blocks from Quickpart in word | jasserin | Word VBA | 0 | 06-05-2013 12:55 PM |
Word - Attach Building Blocks | namedujour | Word | 0 | 04-04-2011 09:59 AM |