Edit a publisher text box with VBA?

wackywoo105

Registered User.
Local time
Today, 12:19
Joined
Mar 14, 2014
Messages
203
I'm currently using the following to edit a publisher document using access VBA.

Code:
 [COLOR=black][FONT=Verdana]For Each pubShape In pubDoc.Pages(1).Shapes
    If pubShape.HasTextFrame Then
        If pubShape.Name = "Text Box 440" Then pubShape.TextFrame.TextRange.Text = Item1
        If pubShape.Name = "Text Box 441" Then pubShape.TextFrame.TextRange.Text = Item2
        If pubShape.Name = "Text Box 442" Then pubShape.TextFrame.TextRange.Text = Item3
        If pubShape.Name = "Text Box 443" Then pubShape.TextFrame.TextRange.Text = Item4
        If pubShape.Name = "Text Box 444" Then pubShape.TextFrame.TextRange.Text = Item5
        If pubShape.Name = "Text Box 445" Then pubShape.TextFrame.TextRange.Text = Item6
        If pubShape.Name = "Text Box 446" Then pubShape.TextFrame.TextRange.Text = Item7
        If pubShape.Name = "Text Box 447" Then pubShape.TextFrame.TextRange.Text = Item8
    End If
Next[/FONT][/COLOR]
Obviously there are a lot of shapes/boxes etc in the document and this code is very inefficient and takes a few moments to complete. Is there a way to directly reference a text box and change its value. For word I have been using bookmarks but this doesn’t seem to work with publisher.

I’m looking for something like pubshape.Value(“text Box 440”) = Item1 but cannot find the correct syntax.
 
I've never needed to program anything in Publisher but the object references between Office products are similar (to an extent).

I've got publisher on my machine (which I never use) so send me the file so I can see what objects you're trying to reference.

NB: It would be more beneficial to have a good naming convention going. Default names like "Text Box X" aren't best practice.
 
Probably
pubDoc.Pages(1).Shapes("Text Box 440")

or

pubDoc.Pages(1).Shapes("[Text Box 440]")


or


pubDoc.Pages(1).Shapes("Text_Box_440")
 

Users who are viewing this thread

Back
Top Bottom