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 / July 2005

Tip: Looking for answers? Try searching our database.

Checking for RangeShapes in a header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roderick O'Regan - 30 Jul 2005 01:48 GMT
Can anyone nudge me in the right direction with the following problem,
please?

I have a document with odd and even pages.

Every page has a header graphic.

I need to insert a landscape page anywhere after page 1 - this I can
manage OK.

Now I need to go into both the odd and even headers of the landscape
section.

I insert a page break command to display both odd and even pages of
the new section.

Then I go to each of the headers and unlink them from the previous.

Next I need to check if there is a shape range in both the odd and
even headers and delete it. I think I might be able to use the
following commands:
With Selection

.Sections(1).Headers(wdHeaderFooterPrimary).Range.ShapeRange.Select
       .Delete

.Sections(1).Headers(wdHeaderFooterEvenPages).Range.ShapeRange.Select
       .Delete
   End With

And here is the problem:

If, for some reason there isn't a ShapeRange in one of the headers
then one of the commands show above causes Word to crash and therefore
I don't think an On Error statement is appropriate as it's not a
runtime error.

What I am trying to compose is a statement which says "If there is a
ShapeRange in the Primary Header of this section then delete it.
Otherwise, go to the Even Pages of the section header, check if there
is a shape range there and delete it"

Easy to write in pseudo code but I'm baffled on how to write it in
VBA!

Any help on this, please?

Regards

Roderick
Jezebel - 30 Jul 2005 04:59 GMT
The key to your problem is the use of the Selection. You don't need it. Work
directly with the Ranges themselves. Separately, don't understand your
concern about error-handling. The error caused if the ShapeRange is empty is
indeed a runtime error, which you can trap or ignore.

Simplest would be something like --

On error resume next
With Selection.Sections(1)
      .Headers(wdHeaderFooterPrimary).Range.ShapeRange.Delete
      .Headers(wdHeaderFooterEvenPages).Range.ShapeRange.Delete
End With

If you really want to check if the ShapeRange is empty, you can use

If  .Headers(wdHeaderFooterPrimary).Range.ShapeRange.Count > 0 then ...

> Can anyone nudge me in the right direction with the following problem,
> please?
[quoted text clipped - 46 lines]
>
> Roderick
Roderick O'Regan - 30 Jul 2005 13:03 GMT
Thanks Jezebel.

Word was crashing when it encountered the ....ShapeRange.Select
command as shown above. Not the runtime error message box.

However, thanks to your suggestion on deleting the Select and
replacing it with Delete does the trick. No crashing. Shapes are
deleted.

Thanks again.

Regards

Roderick

>The key to your problem is the use of the Selection. You don't need it. Work
>directly with the Ranges themselves. Separately, don't understand your
[quoted text clipped - 63 lines]
>>
>> Roderick

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.