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 / August 2007

Tip: Looking for answers? Try searching our database.

ShapeRange Selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roderick O'Regan - 02 Aug 2007 00:55 GMT
The following snippet is part of a larger procedure which places
AutoText graphics in a header and then moves them to the correct
location:
   ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader

   'enters the autotext graphic located in the attached Template
   ActiveDocument.AttachedTemplate.AutoTextEntries(pString).Insert _
           Where:=Selection.Range, RichText:=True

   'first select the graphic

ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.ShapeRange.Select

   With Selection.ShapeRange
       .RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
       .RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
       .Left = CentimetersToPoints(2.5)
       .Top = CentimetersToPoints(1.99)
       .WrapFormat.AllowOverlap = True
   End With

If I run the template all works correctly.

However, if I open the template and then run this procedure to test
the code I get an error 4605 telling me that the
"RelativeHorizontralPosition method or property is not available
because the drawing operation cannot be applied to the current
selection"

The graphic (ShapeRange) is shown as selected.

I then Exit at the error message dialog, close the Header/Footer view
and try it again. It now works correctly from the second time onwards.

Could someone explain why this is happening, please?

Roderick O'Regan
Jean-Guy Marcil - 02 Aug 2007 03:20 GMT
Roderick O'Regan was telling us:
Roderick O'Regan nous racontait que :

> The following snippet is part of a larger procedure which places
> AutoText graphics in a header and then moves them to the correct
[quoted text clipped - 33 lines]
>
> Could someone explain why this is happening, please?

Try not to use the ActivePane and Selection.

Instead, try something like this:

'_______________________________________
Dim rgeHeader As Range
Dim shpHeader As Shape

Set rgeHeader =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
rgeHeader.Collapse wdCollapseStart

'enters the autotext graphic located in the attached Template
ActiveDocument.AttachedTemplate.AutoTextEntries("Test").Insert _
   Where:=rgeHeader, RichText:=True

Set rgeHeader = rgeHeader.Sections(1).Headers(wdHeaderFooterPrimary).Range
'rgeHeader.Select
Set shpHeader = rgeHeader.ShapeRange(1)

With shpHeader
   .RelativeHorizontalPosition = _
       wdRelativeHorizontalPositionPage
   .RelativeVerticalPosition = _
       wdRelativeVerticalPositionPage
   .Left = CentimetersToPoints(2.5)
   .Top = CentimetersToPoints(1.99)
   .WrapFormat.AllowOverlap = True
End With
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Roderick O'Regan - 02 Aug 2007 22:43 GMT
Thanks Jean-Guy for the help.

Is your solution then, in this case, to use ranges rather than
selections?

It seems very odd how it works in selection - or doesn't! In one
instance it doesn't recognise the Relative position command and then
it does the second time around. Weird!

Roderick

>Roderick O'Regan was telling us:
>Roderick O'Regan nous racontait que :
[quoted text clipped - 67 lines]
>End With
>'_______________________________________
Jean-Guy Marcil - 03 Aug 2007 02:17 GMT
Roderick O'Regan was telling us:
Roderick O'Regan nous racontait que :

> Thanks Jean-Guy for the help.
>
[quoted text clipped - 4 lines]
> instance it doesn't recognise the Relative position command and then
> it does the second time around. Weird!

I always avoid the Selection object (Except when there are no other choice,
of course), and I especially want to avoid the ActivePane method  to access
headers/footers because too often I had problems when doing so.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
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.