none
WORD 2013 this method or property is not available because this command is not available for reading RRS feed

  • Question

  • Hi,

    I recieve "this method or property is not available because this command is not available for reading" when doing either of the following where globalrange is a word.range:

    With GlobalRange.Paragraphs
                    .LeftIndent = 0
                    .RightIndent = 0
                    .TabStops.ClearAll()
                End With

    Above throws exception as .tabstops.clearall() and can be worked around by looping the paragraphs collection

                    R = WDDoc.Range
                    R.Start = GlobalRange.Start
                    R.End = GlobalRange.End
                    R.InsertBefore(vbCrLf)

    Above throws the exception at r.InsertBefore(vbcrlf).

    This is code which works for all other versions of office 97-2010.

    Can someone point me in the right direction?

    Monday, February 18, 2013 3:31 PM

Answers

  • Hi Rob

    More on this...

    Apparently, Word is somehow seeing the second window as being in the "Reading mode", rather than Print Layout. Try switching explicitly to Print Layout view after processing the Header/Footer:

      HF.ActiveWindow.View = wdPrintView


    Cindy Meister, VSTO/Word MVP, my blog


    Wednesday, February 20, 2013 3:40 PM
    Moderator

All replies

  • Hi Rob

    What you're seeing is due to a change in Word 2013. It's mentioned at the end of this blog article
    http://blogs.msmvps.com/wordmeister/2013/02/04/word-2013-the-layout-options/

    And also discussed here

    http://answers.microsoft.com/en-us/office/forum/office_2013_release-word/word-2013-ignores-tab-stops-beyond-right-indent/34adc7e2-17df-4399-8f7f-bbcbf507ae29

    The only way you can continue to use tab stops as in older versions is explained a bit higher up in the blog article.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 18, 2013 3:57 PM
    Moderator
  • Thanks for the reply, but I'm not sure it's the same issue.

    All documents are generated from a 97-2003 template. The RTF is then pasted to the document.  Similar code to:

    With GlobalRange.Paragraphs
                    .LeftIndent = 0
                    .RightIndent = 0
                    .TabStops.ClearAll()
                End With

    exists elsewhere with separate tabs being placed below the clear all. If I loop globalrange.paragraphs I don't recieve an exception, this will subsequently allow the above code to run without throwing the exception, similarly with

                    R = WDDoc.Range
                    R.Start = GlobalRange.Start
                    R.End = GlobalRange.End
                    R.InsertBefore(vbCrLf)
    Why is it only an issue the first time it's used in the document? All my documents have the layout options as if created in word97 when I examine the layout under Advanced in word


    • Edited by _PWS_ Monday, February 18, 2013 4:16 PM
    Monday, February 18, 2013 4:13 PM
  • Hi Rob

    You're right, sorry, I don't know what my brain was seeing...

    What's the RTF you're talking about pasting into the document? If you leave out this step (so there's no RTF going into the document) does the code work? (In other words, I'm wondering whether Word 2013 is having problems with the RTF, a format which MS has "deprecated" and is no longer maintaining for newer versions of Word.)

    What, more exactly does GlobalRange represent?


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 18, 2013 4:39 PM
    Moderator
  • Hi Cindy,

    Apolgies this isn't an RTF issue, these document is dynamically created by setting fonts, colours, text etc in differing ranges. I can see that this has worked correctly by maximising the document on the taskbar.

    Looking firstly at

       R = WDDoc.Range
       R.Start = GlobalRange.Start
       R.End = GlobalRange.End
       R.InsertBefore(vbCrLf)

    GlobalRange represents the entire contets of the document (excluding Header & Footers) which forms a tab separated table, I am then attempting to insert a vbCrLF before this entire section before going on to call ConvertToTable.

    Secondly:

    With GlobalRange.Paragraphs
       .LeftIndent = 0
       .RightIndent = 0
       .TabStops.ClearAll()
    End With

    The error occurs when similarly I have a document built with word.ranges, again I can see this has worked. However when I attempt to clear the TabStops prior to resetting them the exception is thrown. As described I can work around the second issue by doing:

    For I as integer = 1 to GlobalRange.Paragraphs.Item(i)
         With GlobalRange.Paragraphs.Item(i)
            .LeftIndent = 0
            .RightIndent = 0
            .TabStops.ClearAll()
         End With
    next

    This will then allow other range that follow and are appended to the document to use the original code, implying that this could be solved by pre-setting something?

    Monday, February 18, 2013 5:06 PM
  • Hi Rob

    Sorry if I appear dense, but, just because something "looks right" on screen doesn't mean it IS right in the document structures.

    To illustrate my point (knowing it's NOT your problem): A text document can be opened or pasted into Word that was generated by a non-Windows system. Let's say an old main frame. It uses a combination of Chr(10)&Chr(13) to generate new line + carriage feed. Word can open this and it looks quite normal. But due to the "unexpected" combination of characters, certain things won't work. And you only become aware that the document isn't "right" when you try to do these things.

    That's why I asked about the RTF and for you to test WITHOUT whatever it is you're pasting into the document. The RTF could be carrying something that's not visible to you, but is causing Word to "choke".

    By the same token, I'd want to know how you "built a document with Word ranges".

    FWIW I just tested Tabstop.ClearAll on a Word 2013 document I set up as a quick test. I assigned various tab stops to this and that paragraph (and set of paragraphs) then ran:

       ActiveDocument.Content.Paragraphs.TabStops.ClearAll

    It worked with absolutely no problem: all the tab stops in the document were removed and no error message.

    Ditto with inserting a new paragraph before a "tab table" as the only content in a document:

      ActiveDocument.Content.InsertBefore vbcrlf

    So the problem has to have something to do with the document...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 18, 2013 5:38 PM
    Moderator
  • I set about recreating the issue from scratch. In word2000 I creted a new blank document and saved it as template.dot. I then created a second blank document and called it source.doc. The errors should be reproducable with the following code, when using Word2013, all other version are ok.

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim WDApp As Word.Application = CreateObject("Word.Application")
    
            WDApp.Visible = True
    
            Dim Doc As Word.Document = WDApp.Documents.Add("c:\template.dot")
    
            Dim HF As Word.Document = WDApp.Documents.Open("c:\source.doc", ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False)
    
            Doc.Sections.First.Headers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText = HF.Sections.First.Headers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText
            Doc.Sections.First.Footers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText = HF.Sections.First.Footers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText
    
            HF.Saved = True
            HF.Close()
    
            Dim Range As Word.Range = Doc.Range
    
            Try
                Range.InsertBefore("vbCrLf")
                'Range.Paragraphs.TabStops.ClearAll() 'Either throw the exception
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
            End Try
    
            WDApp.Quit()
        End Sub


    Removing:

    Doc.Sections.First.Headers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText = HF.Sections.First.Headers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText
            Doc.Sections.First.Footers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText = HF.Sections.First.Footers.Item(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.FormattedText

    Will prevent the exception, so how should I amend the code to make it 2013 friendly?




    Tuesday, February 19, 2013 2:38 PM
  • Hi Rob

    Now I can repro. Interesting...

    This works for me:

               ' rng.InsertBefore "vbCrLf"
                rng.Collapse wdCollapseStart
                rng.Text = vbCrLf


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 20, 2013 8:26 AM
    Moderator
  • Hi Rob

    More on this...

    Apparently, Word is somehow seeing the second window as being in the "Reading mode", rather than Print Layout. Try switching explicitly to Print Layout view after processing the Header/Footer:

      HF.ActiveWindow.View = wdPrintView


    Cindy Meister, VSTO/Word MVP, my blog


    Wednesday, February 20, 2013 3:40 PM
    Moderator
  • Hi Cindy,

    Even with the HF.ActiveWindow.View = wdPrintView inserted the error still occurs. Inserting

    rng.Collapse wdCollapseStart
    rng.Text = vbCrLf

    also isn't suitable as doesn't solve the

    Range.Paragraphs.TabStops.ClearAll()

    error, plus the range object doesn't format properly for me.

    Any other ideas?

    Friday, March 1, 2013 12:18 PM