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

Re: ShapeRange Selection by Jean-Guy

Jean-Guy
Wed Aug 01 21:20:45 CDT 2007

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
> 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?

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
'_______________________________________

--

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



Re: ShapeRange Selection by Roderick

Roderick
Thu Aug 02 16:43:41 CDT 2007

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

On Wed, 1 Aug 2007 22:20:45 -0400, "Jean-Guy Marcil"
<DontEvenTry@NoSpam> wrote:

>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
>> 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?
>
>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
>'_______________________________________

Re: ShapeRange Selection by Jean-Guy

Jean-Guy
Thu Aug 02 20:17:46 CDT 2007

Roderick O'Regan was telling us:
Roderick O'Regan nous racontait que :

> 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!

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.

--

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