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
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
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
msWord.Selection.ShapeRange.TextEffect.Text = WordAfter
Jitendra Faye replied to Brian (Mac) Mac Gregor on 25-Oct-11 12:07 AM
Try this VBA=
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
If oTempl Is Nothing Then
MsgBox "Building Blocks.dotx not found"
For idx = 1 To oTempl.BuildingBlockEntries.Count
Set tempBBE = oTempl.BuildingBlockEntries(idx)
If InStr(LCase(tempBBE.Name), LCase(BBEname)) Then
Set oBBE = tempBBE
If oBBE Is Nothing Then
MsgBox BBEname & " not found"
oBBE.Insert where:=oRg, RichText:=True
Try this and let me know
Srikanth 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’
Refer this link
, FontSize:=36, _
, Left:=10, Top:=10).
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 Srikanth 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-
For more help follow this link also-
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( _
Category:="Book Titles", _
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
Brian (Mac) Mac Gregor replied to Jitendra Faye on 04-Nov-11 04:38 AM
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.