Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Adding a text box script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oz Springs - 21 Dec 2004 13:47 GMT
I have created a template that includes the insertion of a text box. I am
using Word 2004 (Mac) and the template is to be used on PCs.

The problems is that the text box draw does not work on a PC using Word 2002
and Windows XP Professional. The offending line is:

________________________

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 42.55, _
       667.65, 340#, 69#).Select
_______________________
And the error message is:

Run-time error Œ-2147024891 (80070005)¹
This member cannot be accessed in this view.
______________________

Can anyone tell me what is wrong and, better still, how to correct it?

Thanks for any help

Oz

PS I am wondering, as ³in this view² is something I think I can understand
in the cryptic error message, whether the client has the form open in Normal
rather than Page Layout view, or maybe in header or footer. How can I stop
him from trying to run this macro in anything other than Page Layout view?
Jay Freedman - 21 Dec 2004 15:54 GMT
Hi Oz,

I can reproduce the error message if the selection is in a header/footer,
and a similar one if the selection is in a footnote/endnote. It doesn't
matter whether the view is Normal, as the selection of the textbox will
force the view to Print Layout automatically.

Add this at the beginning of the macro to get to the right view:

If Selection.Information(wdInHeaderFooter) Or _
  Selection.Information(wdInCommentPane) Or _
  Selection.Information(wdInFootnoteEndnotePane) Then
  With ActiveDocument.ActiveWindow.View
      .Type = wdPrintView  ' not strictly necessary...
      .SeekView = wdSeekMainDocument
  End With
End If

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> I have created a template that includes the insertion of a text box.
> I am using Word 2004 (Mac) and the template is to be used on PCs.
[quoted text clipped - 24 lines]
> or footer. How can I stop him from trying to run this macro in
> anything other than Page Layout view?
Jay Freedman - 21 Dec 2004 16:43 GMT
I meant to add this bit before sending my response:

It's probably a better idea to avoid selecting things and working with the
Selection object altogether, if that's possible. There are only a few things
you can do with the Selection that can't be done with Range objects and
other objects.

You'd start by declaring a Shape object

  Dim myTextBox as Shape

and assign the result of the .AddTextbox method to it; use the Anchor
parameter to specify the anchor location from which the Left and Top are
measured:

  Set myTextBox = ActiveDocument.Shapes.AddTextbox( _
       Orientation:=msoTextOrientationHorizontal, _
       Left:=42.55, Top:=667.65, _
       Width:=340#, Height:=69#, _
        Anchor:=ActiveDocument.Paragraphs(1).Range)

Then you can manipulate the myTextBox object in any way you need to -- add
text, format the TextFrame, etc. -- all without touching the Selection. It
won't matter what's in the active window, view, or pane.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi Oz,
>
[quoted text clipped - 44 lines]
>> or footer. How can I stop him from trying to run this macro in
>> anything other than Page Layout view?
Oz Springs - 21 Dec 2004 17:12 GMT
Hi Jay

Thank you very for your help. I haven¹t checked it out yet, but can you
confirm that you have set the textbox anchor to the first paragraph so that
it won¹t move around? If so, this is a bonus because I was going to set it
to stay put and you have saved me the bother of sorting that out as well.

Kind regards

Oz  

On 21/12/04 16:43, in article uuet#w35EHA.828@TK2MSFTNGP14.phx.gbl, "Jay
Freedman" <jay.freedman@verizon.net> wrote:

> I meant to add this bit before sending my response:
>
[quoted text clipped - 20 lines]
> text, format the TextFrame, etc. -- all without touching the Selection. It
> won't matter what's in the active window, view, or pane.
Jay Freedman - 21 Dec 2004 18:28 GMT
Hi Oz,

Actually, I chose to anchor the textbox in the first paragraph because
that's a simple thing to do in an example. You can choose any spot in the
document that suits your needs.

The relationship between an object's position and its anchor is more than a
little strange. The only hard-and-fast rule is that the object must be on
the same page as the anchor. If text is added before the anchor range that
moves the anchor to the next page, the object will also jump to the next
page.

Within that restriction, there's no foolproof way to lock to location of the
object on that page. If you "lock the anchor" either programmatically or
through the Format Object dialog, you prevent only the movement of the
anchor from one paragraph to another; the object itself can still be dragged
to a new position on the page.

If you want the object to stay on the first page (or the first page of any
particular section), you can anchor it in the First Page Header instead of
the regular text (the object's position can still be anywhere on the page).
That will put it mostly out of harm's way -- the user will have to go to
some trouble just to select it. As a further protection, you can write
macros to (mostly) prevent user access to the header (see
http://word.mvps.org/FAQs/Customization/ProtectWord2000PlusHeader.htm)
unless their security setting disables macros.

That may be more than you really wanted to know, but some day you'll need
it. ;-)

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi Jay
>
[quoted text clipped - 35 lines]
>> Selection. It won't matter what's in the active window, view, or
>> pane.
Oz Springs - 21 Dec 2004 20:40 GMT
Thank you for this information. It should be safer to put the anchor on the
top paragraph mark in order to stop it moving up and down if text above it
changes, though this is not guaranteed.

It would be good if Microsoft could make text boxes less fragile, especially
for people creating templates, such as this one, to be used by many people
who don¹t know Word and its idiosyncrasies.

Text box text can¹t be seen in galley view and it is so easy to just delete
it without knowing you have done so (oh, these blank paragraph marks look so
messy...). Also, we should be able to ³lock² a text box in a position and on
a particular page without relying on those moveable paragraph marks. This
template will be used on a pre-printed, single page form and the text box
has to rest upon a stripe of colour. Otherwise I¹d avoid text boxes like the
plague in templates.

Wouldn¹t it be nice if Microsoft found a way of fixing this problem?

Many thanks

Oz  

On 21/12/04 18:28, in article OyXfPr45EHA.4004@tk2msftngp13.phx.gbl, "Jay
Freedman" <jay.freedman@verizon.net> wrote:

> Hi Oz,
>
[quoted text clipped - 25 lines]
> That may be more than you really wanted to know, but some day you'll need
> it. ;-)

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.