Results 1 to 13 of 13
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    range not selected/active (WordXP SP3)

    Hi

    I have the following code that works with & formats & inserts a watermark in the header.
    it was working fine. now it just bombs with the following error number '4605', error message 'The relativeHorizontalPosition method or property is not available because the drawing operation cannot be applied to the current selection.'

    heres my code:
    any suggestions would be greatly appreciated....diana :-)

    'set header ranges
    Set rngFirstHeader = ActiveDocument.Sections(x).Headers(wdHeaderFooterF irstPage).Range

    Private Function HeaderInsertFirstPage()
    Dim strRAType As String

    'error handling
    On Error GoTo HeaderInsertFirstPageError
    gsErrProcedure = "HeaderInsertFirstPage"

    'define a range to only include autotext entry name
    With rngFirstHeader
    .Select
    .Collapse Direction:=wdCollapseEnd
    End With
    With Selection
    .Collapse Direction:=wdCollapseEnd
    End With

    'in header add autotext entry
    If AddIns(strGlobalAutoTextTemplate).Installed Then
    Templates(strGlobalAutoTextTemplate).AutoTextEntri es(strHeader1stPage).Insert Where:=Selection.Range, RichText:=True
    End If

    'redefine range as header 1st page to include all in header
    Set rngFirstHeader = ActiveDocument.Sections(x).Headers(wdHeaderFooterF irstPage).Range

    'if print option is copy or draft - position watermark text correctly on page
    If gsPrintOptionType = "Copy" Or gsPrintOptionType = "Draft" Then

    'for formatting purposes obtain current section page orientation
    intPageOrientation = ActiveDocument.Sections(x).PageSetup.Orientation

    'format object
    With rngFirstHeader
    .ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    End With
    With rngFirstHeader
    .ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionPage
    End With

    'if page setup orientation is landscape -
    'format object within page orientation & margins
    If intPageOrientation = 1 Then

    'if print option is draft - format
    If gsPrintOptionType = "Draft" Then
    With rngFirstHeader
    .ShapeRange.Left = CentimetersToPoints(5.59)
    .ShapeRange.Top = CentimetersToPoints(-2.29)
    End With
    End If

    'if print option is copy format
    If gsPrintOptionType = "Copy" Then
    With rngFirstHeader
    .ShapeRange.Left = CentimetersToPoints(5.59)
    .ShapeRange.Top = CentimetersToPoints(0.25)
    End With
    End If

    Else
    'else page setup orientation = Potrait - format within page
    With rngFirstHeader
    .ShapeRange.Left = CentimetersToPoints(2)
    .ShapeRange.Top = CentimetersToPoints(2)
    End With
    End If
    End If


    end sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: range not selected/active (WordXP SP3)

    There are lots of variables in your code that are not defined in the part you posted. that makes it hard to test. Could you post a copy of the document, with the text replaced by dummy text if necessary?

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    range not selected/active - Part 1 attachment

    Hans

    Please find attached my sample code.
    I've also attached a normal.dot that contain 2 autotext entries. place the normal.dot in your Words global startup path.
    I havent attached a sample Word document. Just create a document with several sections formatted with different 1st page header - > run the code on that document. result for me is the code always bombs on section 2 primary.
    the code will probaly run & work for you. let me know how you go.
    diana

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    range not selected/active - Part 2 attachment

    Part 2 attachment- amend to a template.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: range not selected/active - Part 1 attachment

    I created a document with three sections, with first page different.

    There were still lots of undeclared variables, but after declaring them, the code ran without a hitch. I experimented with linking and unlinking headers - no difference. So I don't know what's wrong <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: range not selected/active - Part 1 attachment

    hi hans

    i had figured as much that it will work for you...
    then do you have any code that works with either
    1. header ranges
    2. objects - such as my watermarks?

    diana :-)

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: range not selected/active - Part 1 attachment

    I guess the answer is no, nothing in particular.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: range not selected/active - Part 1 attachment

    I don't get that error message either, but there is something strange. It repeatedly inserts the WordArt over and over. I think this is because your HeaderFooterInsert procedure looks at the count of InlineShape objects rather than (drawing layer) Shape objects. If your WordArt objects are being inserted as InlineShape objects, then this could explain why you get errors with the ShapeRange. Actually, trying to simulate that problem gives me error number 5852 ("object not available"), but maybe you will get different results in your environment.

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: range not selected/active - Part 1 attachment

    There is a mismatch between your error message, which refers to a selection, and the code, which uses ranges. Are you sure that's the correct snippet/version of code?

  10. #10
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: range not selected/active - Part 1 attachment

    hi jefferson

    the error message i'm receiving is to the effect of the 'current object is not selected'
    'The relativeHorizontalPosition method or property is not available because the drawing operation cannot be applied to the current selection.'
    which could also be interpretated as 'object not available' - what do you think?
    yes thats the correct code? so perhaps there maybe a mismatch which i may not have picked up on?

    Diana

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: range not selected/active - Part 1 attachment

    I just don't understand why it's complaining about a selection. The error is on the bold line below?
    <pre>Set rngFirstHeader = ActiveDocument.Sections(x).Headers(wdHeaderFooterF irstPage).Range

    'if print option is copy or draft - position watermark text correctly on page
    If gsPrintOptionType = "Copy" Or gsPrintOptionType = "Draft" Then

    'for formatting purposes obtain current section page orientation
    intPageOrientation = ActiveDocument.Sections(x).PageSetup.Orientation

    'format object
    With rngFirstHeader
    .ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    End With</pre>

    No Selection in sight!

    Added: I tested with the code pasted into your template as an attached template to a new document. If you are running your code from a global template, you will need to open it in order to Debug on the correct line.

  12. #12
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: range not selected/active - Part 1 attachment

    Hi Jefferson - yes thats the line I get the error on as well.
    This code has been working OK for 3 years. its only now bombing out. We have recently upgraded from Word97 to WordXP. I dont really understand?
    Do you have any other suggestions of code that I can work with in terms of formatting the range - objects?

    Diana

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: range not selected/active - Part 1 attachment

    Actually I don't get any error, I was just trying to clarify where you were getting the error.

    I'm wondering whether there is some other shape lurking in your headers? Try out this diagnostic code and see if you get the results you would expect:
    <pre>Sub ShapeDetector()
    ' Report out contents of headers
    Dim intCount As Integer
    For intCount = 1 To ActiveDocument.Sections.Count
    ShapeDump intCount, wdHeaderFooterFirstPage
    ShapeDump intCount, wdHeaderFooterPrimary
    Next
    End Sub

    Sub ShapeDump(intSection As Integer, lngHdr As WdHeaderFooterIndex)
    ' Output shape information to Immediate Window
    Debug.Print "Report for Section " & intSection & ", Header " & lngHdr
    Dim shpR As ShapeRange, inlS As InlineShapes, intLoopCount As Integer
    Set shpR = ActiveDocument.Sections(intSection).Headers(lngHdr ).Range.ShapeRange
    With shpR
    Debug.Print "ShapeRange contains " & .Count & " shapes."
    If .Count > 0 Then
    For intLoopCount = 1 To .Count
    Debug.Print " msoShapeType: " & .Item(intLoopCount).Type
    Next
    End If
    End With
    Set shpR = Nothing
    Set inlS = ActiveDocument.Sections(intSection).Headers(lngHdr ).Range.InlineShapes
    With inlS
    Debug.Print "InlineShapes contains " & .Count & " inline shapes."
    If .Count > 0 Then
    For intLoopCount = 1 To shpR.Count
    Debug.Print " wdInlineShapeType: " & .Item(intLoopCount).Type
    Next
    End If
    End With
    Set inlS = Nothing
    End Sub</pre>

    Do you get the number of shapes and inline shapes you expect before and/or after running your code?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •