Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-02-2016, 02:20 PM
jc491's Avatar
jc491 jc491 is offline VBA Word -  Building Block (AutoText) - Array - Replace Text with Specific Building Blocks Windows 10 VBA Word -  Building Block (AutoText) - Array - Replace Text with Specific Building Blocks Office 2016
VBA Novice
VBA Word -  Building Block (AutoText) - Array - Replace Text with Specific Building Blocks
 
Join Date: Sep 2015
Location: UK
Posts: 55
jc491 is on a distinguished road
Default 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
I have referenced the following - as well

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
Reply With Quote
 

Tags
building block, vba word

Thread Tools
Display Modes


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
VBA Word -  Building Block (AutoText) - Array - Replace Text with Specific Building Blocks Word - Attach Building Blocks namedujour Word 0 04-04-2011 09:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:11 PM.


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