VB 6.0 - Changing WordArt in Watermarks using VBA

Asked By Brian (Mac) Mac Gregor on 24-Oct-11 11:05 AM
I have a VB6 system which interacts with MSWord 2000/2003 via VBA.  I have a process that changes the WordArt text in the Watermark in the headers and it works fine apart from when there is a a header/watermark in the first page of a section that differs from the remainder of the section.  No matter what I try I cannot change the WordArt text in the first page of a section.

My code has gone through numerous changes but is essentially as generated when recording a macro and is as follows: 

    If msWord.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    End If
    If msWord.ActiveWindow.ActivePane.View.Type = wdNormalView Or _
        msWord.ActiveWindow.ActivePane.View.Type = wdOutlineView Or _
        msWord.ActiveWindow.ActivePane.View.Type = wdMasterView Then
        msWord.ActiveWindow.ActivePane.View.Type = wdPageView
    End If
    counter = 1
    msWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    With msWord.ActiveDocument.sections(WordSection) 'localsub)
        fred = .headers(wdHeaderFooterPrimary).Range.ShapeRange(counter).name
        If RTrim(Mid(fred, 1, 9)) <> "WordArt 1" Then 
            counter = counter + 1
            If counter < 10 Then '0 Then
                GoTo WordWaterMarkChangeLoopBack
            End If
        End If
    End With
    msWord.Selection.ShapeRange.TextEffect.Text = WordAfter

Jitendra Faye replied to Brian (Mac) Mac Gregor on 25-Oct-11 12:07 AM
Try this VBA=

This works:

Sub InsertWatermark()
Dim oRg As Range
Dim oTempl As Template, tempTempl As Template
Dim oBBE As BuildingBlock, tempBBE As BuildingBlock
Dim idx As Long
Dim BBEname As String

BBEname = "CONFIDENTIAL 1" ' name of watermark to insert


Set oRg = _
oRg.Collapse wdCollapseStart ' <== MUST DO THIS

For Each tempTempl In Templates
If InStr(LCase(tempTempl.Name), "building blocks.dotx") Then
Set oTempl = tempTempl
Exit For
End If

If oTempl Is Nothing Then
MsgBox "Building Blocks.dotx not found"
Exit Sub
End If

For idx = 1 To oTempl.BuildingBlockEntries.Count
Set tempBBE = oTempl.BuildingBlockEntries(idx)
If InStr(LCase(tempBBE.Name), LCase(BBEname)) Then
Set oBBE = tempBBE
Exit For
End If

If oBBE Is Nothing Then
MsgBox BBEname & " not found"
Exit Sub
End If

oBBE.Insert where:=oRg, RichText:=True
End Sub

Try this and let me know
Sri K replied to Brian (Mac) Mac Gregor on 25-Oct-11 01:45 AM
This is an example of an output for the word “DRAFT”. The initial statement defines the font, text, and starting position on the page. It is just a piece of text at this point that is defined using WordArt. WordArt is part of the Microsoft Office package and is activated by selecting on the toolbar, ‘Insert’, ‘Picture’, ‘WordArt’.

ActiveSheet.Shapes.AddTextEffect(PresetTextEffect:=msoTextEffect1, _
    Text:="DRAFT", FontName:="Arial Black", FontSize:=36, _
    FontBold:=False, FontItalic:=False, Left:=10, Top:=10).Select
Refer this link http://www.codetoad.com/vba_watermark.asp
Brian (Mac) Mac Gregor replied to Jitendra Faye on 25-Oct-11 02:36 AM

Thanks for the response.

This gives me an error on the definition of BuildingBlock.


Brian (Mac) Mac Gregor replied to Sri K on 25-Oct-11 02:38 AM

Thanks for the response.

This inserts DRAFT in the first section but I actually want to replace the text that is already in the Watermark as WordArt


Jitendra Faye replied to Brian (Mac) Mac Gregor on 25-Oct-11 03:22 AM
You can create object of BuildingBlockEntries like this-

Sub AddCustomBuildingBlock()

    Dim objTemplate As Template
    Dim objBB As BuildingBlock
    Dim objRange As Range

    ' Set the template to store the building block
    Set objTemplate = ActiveDocument.AttachedTemplate

    ' Collapse the range, set the range, and add the text
    Set objRange = Selection.Range
    objRange.Text = "Building blocks for the technically challenged"

    ' Add the building block to the template
    Set objBB = objTemplate.BuildingBlockEntries.Add( _
        Name:="Title", _
        Type:=wdTypeCustomHeaders, _
        Category:="Book Titles", _

End Sub
 For more help follow this link also-


Brian (Mac) Mac Gregor replied to Jitendra Faye on 25-Oct-11 04:47 AM

It give me "User defined type not defined" for BuildingBlock


Jitendra Faye replied to Brian (Mac) Mac Gregor on 25-Oct-11 04:59 AM
Each BuildingBlock object is a member of the http://msdn.microsoft.com/en-us/library/bb256540%28v=office.12%29.aspx and http://msdn.microsoft.com/en-us/library/bb256535%28v=office.12%29.aspx collections. Building blocks are stored in Microsoft Office Word templates. Therefore, to access the building blocks available for a document, you need to access an attached template. Built-in building blocks are stored in the template named "Building Blocks.dotx".

For more help follow this link-

Brian (Mac) Mac Gregor replied to Jitendra Faye on 26-Oct-11 02:13 AM

Once again thanks for your response.

In investigating BuildingBlocks I only see reference to Word 2007 and above.  I am working with Word 2000 and Word 2003.

I am also having trouble understanding how to use it in VB6 so if you can send me a vb6 project using it I would appreciate it.


Brian (Mac) Mac Gregor replied to Jitendra Faye on 03-Nov-11 05:02 AM
Thanks for your help.  Problem solved. Your a star
Jitendra Faye replied to Brian (Mac) Mac Gregor on 03-Nov-11 06:14 AM
You always welcome.
Brian (Mac) Mac Gregor replied to Jitendra Faye on 04-Nov-11 04:38 AM
Hi Vicky

You were so helpful for this that, if you have the time, I would really like you to have a look at my latest problem headed Controlling the MSWord Ribbon from my VB system.


Jitendra Faye replied to Brian (Mac) Mac Gregor on 04-Nov-11 05:25 AM
Hi Mac ,

I am not sure this will help you.

but try this-

you can cutomize using the Office 2007 Custom UI Editor and a Word VBA Template Add-In.

The Office 2007 Custom UI Editor is available for free download from the OpenXMLDeveloper.org:   http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/08/07/7293.aspx

Using the methods described here, ribbon customization can be applied to a single document, all documents based on a particular Word template, or globally using a Word template Add-In. 

Follow this link, here you will get article about this-

Hope this will help you.